Re: threds question with Tk

2020-12-15 Thread Mike


If nobody responds, please supply a stripped down
version of the script that produces the problem.

Maybe get rid of
use threads;
use threads::shared;
use IO::Socket::INET;


Mike


On 12/14/20 7:00 AM, stefano cerbioni wrote:

hi guys
i have created a script because i want a listbox and inside of them i 
want visualize a stream data , i understand for do that is necessary 
use threads first create a stream and second manages a Tk

the problem is  in Tk listbox appear only one time  a data stream
why ??, if anyone have some idea is welcome  thanks at all

this is a my code (perl 5 strawbaerry in windows 10 64bit )

use threads;
use threads::shared;
use Perl::Tidy;
use Tk;
use Tk::LabFrame;
use Tk::ROText;
use strict;
use IO::Socket::INET;
my$x:shared=1;
my$data :shared;
my@workerThreads;
my@otherThreads;
push@workerThreads , threads->create (\&threadSub1) for (1..10);
push@otherThreads , threads->create (\&threadSub2) ;
$_->join() for@workerThreads ;
$_->join() for@otherThreads ;
print("$x\n");
subthreadSub2 {
my$mw = MainWindow->new ;
$mw->geometry( "600x600" );
my$lbox = $mw->Listbox(-height =>500, -width =>500)->pack();
$lbox->insert('end', $data );
MainLoop;
}
subthreadSub1 {
# auto-flush on socket
$| = 1;
# creating a listening socket
my$socket = new IO::Socket::INET (
LocalHost => '127.0.0.1',
LocalPort => '23456',
Proto => 'tcp',
Listen => 5,
Reuse => 1
);
die"cannot create socket $!\n"unless$socket;
print"server waiting for client connection on port 23456 \n";
while(1)
{
# waiting for a new client connection
my$client_socket = $socket->accept();
# get information about a newly connected client
my$client_address = $client_socket->peerhost();
my$client_port = $client_socket->peerport();
print"connection from $client_address:$client_port\n";
# read up to 1024 characters from the connected client
#my $data = "";
$client_socket->recv($data, 1024);
print"received data: $data\n";
my@data_array = split(/;/,$data);
foreach (@data_array) {
return"$_\n";
print"$_\n";
}
# write response data to the connected client
$data = "ok";
$client_socket->send($data);
# notify client that response has been sent
shutdown($client_socket, 1);
}
$socket->close();
}




threds question with Tk

2020-12-14 Thread stefano cerbioni
hi guys
i have created a script because i want a listbox and  inside of them i want
visualize a stream data , i understand for do that is necessary use threads
first create a stream and second manages a Tk
the problem is  in Tk listbox appear only one time  a data stream
why ??, if anyone have some idea is welcome  thanks at all

this is a my code (perl 5 strawbaerry in windows 10 64bit )

use threads;
use threads::shared;
use Perl::Tidy;
use Tk;
use Tk::LabFrame;
use Tk::ROText;
use strict;
use IO::Socket::INET;

my $x:shared=1;
my $data :shared;

my @workerThreads;
my @otherThreads;
push @workerThreads , threads->create (\&threadSub1) for (1..10);
push @otherThreads , threads->create (\&threadSub2) ;
$_->join() for @workerThreads ;
$_->join() for @otherThreads ;

print("$x\n");



sub threadSub2 {
my $mw = MainWindow->new ;
$mw->geometry( "600x600" );
my $lbox = $mw->Listbox(-height =>500, -width =>500)->pack();


$lbox->insert('end', $data );

MainLoop;


}

sub threadSub1 {
# auto-flush on socket
$| = 1;

# creating a listening socket
my $socket = new IO::Socket::INET (
LocalHost => '127.0.0.1',
LocalPort => '23456',
Proto => 'tcp',
Listen => 5,
Reuse => 1
);
die "cannot create socket $!\n" unless $socket;
print "server waiting for client connection on port 23456 \n";

while(1)
{
# waiting for a new client connection
my $client_socket = $socket->accept();

# get information about a newly connected client
my $client_address = $client_socket->peerhost();
my $client_port = $client_socket->peerport();
print "connection from $client_address:$client_port\n";

# read up to 1024 characters from the connected client
#my $data = "";
$client_socket->recv($data, 1024);
print "received data: $data\n";

   my  @data_array = split(/;/,$data);
foreach (@data_array) {
return "$_\n";
  print "$_\n";
}

# write response data to the connected client
$data = "ok";
$client_socket->send($data);

# notify client that response has been sent
shutdown($client_socket, 1);
}

$socket->close();
}


Re: question about stream data and tk

2020-12-09 Thread WILLIAM & ERIKA MARTINEZ
Good morning
I am retired, no longer programming.  Please remove my name/email address from 
your database/emailing list.
Thank you
will

> On 12/09/2020 5:52 AM stefano cerbioni  wrote:
>  
>  
> hi guys  i have  a question
> is  possible insert in listbox a TCP ipStream ? Does anyone  have some 
> examples about it ??
> because I don't know where to start thanks
>  
> 


Re: question about stream data and tk

2020-12-09 Thread Mike



I'm thinking that is not easy - maybe not possible.
I hope you prove me wrong.


Mike


On 12/9/20 6:52 AM, stefano cerbioni wrote:

hi guys  i have  a question
is  possible insert in listbox a TCP ipStream ? Does anyone  have some 
examples about it ??

because I don't know where to start thanks



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




question about stream data and tk

2020-12-09 Thread stefano cerbioni
hi guys  i have  a question
is  possible insert in listbox a TCP ipStream ? Does anyone  have some
examples about it ??
because I don't know where to start thanks


Re: question about change text in frame

2020-12-01 Thread Shlomi Fish
Hi Stefano!

On Sun, 29 Nov 2020 18:49:13 +0100
stefano cerbioni  wrote:

> Hi guys i find in internet  but nothing  , how  is possible change a text
> inside a frame ??
> 
> example i have this frame
> 

Please go over these documents:

* https://github.com/shlomif/how-to-share-code-online

* https://github.com/shlomif/writing-the-perfect-question

Non-runnable / not self-contained fragments make it hard for us to help you.

> 
> my $labeled_frame2 = $mw->LabFrame(-label => "FRAME",-labelside =>
> "bottom")->pack(-fill => "x");
> $labeled_frame2->Label(-text => "de ma de")->pack();
> 
> 
> i try
> with this
>  $labeled_frame2->configure (-text=>"BaoBABB");
> $mw->update();
> 
> but if is a simple  label like this :
> $mw->Label(-text => 'ciao')->pack(-anchor => 'nw');
> work but  in frame not  anyone  has an idea ?? thanks  in advice at all
> ciao



-- 

Shlomi Fish   https://www.shlomifish.org/
https://youtu.be/n6KAGqjdmsk - “Hurt Me Tomorrow”

   rindolf: yeah because Perl’s crypt() is TOTALLY different from all
the other crypt()s. ;)
   Su-Shee: crypts are like snowflakes - no one alike.
  * rindolf has a huge and comprehensive collection of crypts on his disk.

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/




Re: question about change text in frame

2020-11-29 Thread sisyphus
On Mon, Nov 30, 2020 at 5:08 AM Andrew Solomon  wrote:

> Hi Stefano,
>
> From a Google search on "LabFrame" I assume that you're using this module?
>
> https://metacpan.org/pod/distribution/Tk/pod/LabFrame.pod
> and also this (undocumented) module
> https://metacpan.org/source/SREZIC/Tk-804.035/Tk/LabEntry.pm
>
> If that's the case you might want to try contacting Slaven directly:
>
>
If there's nobody here that can provide  a solution, another option is to
ask on perlmonks (https://www.perlmonks.org/?node=Newest%20Nodes) - there
are a few Tk users there.
Best to provide them with a short script that demonstrates the problem.

Cheers,
Rob


Re: question about change text in frame

2020-11-29 Thread Andrew Solomon
Hi Stefano,

>From a Google search on "LabFrame" I assume that you're using this module?

https://metacpan.org/pod/distribution/Tk/pod/LabFrame.pod
and also this (undocumented) module
https://metacpan.org/source/SREZIC/Tk-804.035/Tk/LabEntry.pm

If that's the case you might want to try contacting Slaven directly:

https://metacpan.org/author/SREZIC

Sorry I couldn't be more helpful!

Andrew


On Sun, Nov 29, 2020 at 5:49 PM stefano cerbioni  wrote:

> Hi guys i find in internet  but nothing  , how  is possible change a text
> inside a frame ??
>
> example i have this frame
>
>
> my $labeled_frame2 = $mw->LabFrame(-label => "FRAME",-labelside =>
> "bottom")->pack(-fill => "x");
> $labeled_frame2->Label(-text => "de ma de")->pack();
>
>
> i try
> with this
>  $labeled_frame2->configure (-text=>"BaoBABB");
> $mw->update();
>
> but if is a simple  label like this :
> $mw->Label(-text => 'ciao')->pack(-anchor => 'nw');
> work but  in frame not  anyone  has an idea ?? thanks  in advice at all
> ciao
>


-- 
Andrew Solomon
Director, Geekuni 
P: +44 7931 946 062
E: and...@geekuni.com


question about change text in frame

2020-11-29 Thread stefano cerbioni
Hi guys i find in internet  but nothing  , how  is possible change a text
inside a frame ??

example i have this frame


my $labeled_frame2 = $mw->LabFrame(-label => "FRAME",-labelside =>
"bottom")->pack(-fill => "x");
$labeled_frame2->Label(-text => "de ma de")->pack();


i try
with this
 $labeled_frame2->configure (-text=>"BaoBABB");
$mw->update();

but if is a simple  label like this :
$mw->Label(-text => 'ciao')->pack(-anchor => 'nw');
work but  in frame not  anyone  has an idea ?? thanks  in advice at all
ciao


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: question about perl script

2019-10-30 Thread Rob Coops
This should do:

#!/usr/bin/perl

use strict;
use warnings;

open my $a, '<:encoding(UTF-8)', 'a' or die "Unable to open a: $!";
open my $b, '<:encoding(UTF-8)', 'b' or die "Unable to open b: $!";

my %pair = ();

while ( my $line = <$a> ) {
  my @line = split(" ", $line);
  $pair{$line[0]} = 1;
}

while ( my $line = <$b> ) {
  my @line = split(" ", $line);
  if ( $pair{$line[0]} ) {
next;
  } else {
print $line
  }
}

close $a;
close $b;

A bit simplified of course using strict because as your code grows its the
only way to stay sane.
Now there are a few issues with this, the main one being that this is all
done in memory, so as your files grow you might run into trouble with
memory usage. So you might want to read chunks at a time rather than the
whole file. Also keep in mind that every action (like chomp) takes time
time that in this case is totally not needed, so stripping those pointless
steps out will help make things go faster which certainly as the file sizes
grow will make a difference.

Lastly I would suggest adding comments to the code so you can much more
easily hand this over to the next person that might want to understand what
you are doing or how you are doing that even though you are no longer there
to ask those questions (or after a few years you no longer remember)

Regards,

Rob

On Wed, Oct 30, 2019 at 7:04 AM Uri Guttman  wrote:

> On 10/29/19 10:48 PM, 刘东 wrote:
>
> Dear every one:
> 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.
> Number found where operator expected at carp01_1_both.txt line 44994, near
> "55659 1"
> (Missing operator before  1?)
> Number found where operator expected at carp01_1_both.txt line 44994, near
> "ATCACG55"
> (Do you need to predeclare ATCACG?)
> Number found where operator expected at carp01_1_both.txt line 44994, near
> "55116"
> (Missing operator before 116?)
> syntax error at carp01_1_both.txt line 1, near "979:"
>
>
> it appears that perl is trying to compile one of your data files. show the
> command line where you run your script
>
>
> perl script:
> #!/usr/bin/perl -w
>
> better to use warnings than -w. also use strict is important
>
> open(NAME,"<$ARGV[0]")|| die;
> open(SECON,"<$ARGV[1]")|| die;
> open(SELEC,">$ARGV[2]")|| die;
>
> your die lines should say which file failed to open
>
> uri
>
>


Re: question about perl script

2019-10-29 Thread Uri Guttman

On 10/29/19 10:48 PM, 刘东 wrote:

Dear every one:
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.
Number found where operator expected at carp01_1_both.txt line 44994, 
near "55659 1"

    (Missing operator before  1?)
Number found where operator expected at carp01_1_both.txt line 44994, 
near "ATCACG    55"

    (Do you need to predeclare ATCACG?)
Number found where operator expected at carp01_1_both.txt line 44994, 
near "55    116"

    (Missing operator before     116?)
syntax error at carp01_1_both.txt line 1, near "979:"


it appears that perl is trying to compile one of your data files. show 
the command line where you run your script




perl script:
#!/usr/bin/perl -w

better to use warnings than -w. also use strict is important

open(NAME,"<$ARGV[0]")|| die;
open(SECON,"<$ARGV[1]")|| die;
open(SELEC,">$ARGV[2]")|| die;

your die lines should say which file failed to open

uri



question about perl script

2019-10-29 Thread 刘东
Dear every one:
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.
Number found where operator expected at carp01_1_both.txt line 44994, near 
"55659 1"
(Missing operator before  1?)
Number found where operator expected at carp01_1_both.txt line 44994, near 
"ATCACG55"
(Do you need to predeclare ATCACG?)
Number found where operator expected at carp01_1_both.txt line 44994, near "55  
  116"
(Missing operator before 116?)

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


carp01_1_both.txt:
HISEQ:979:HM2HCBCX2:1:1110:15064:80819 1:N:0:ATCACG 62  123 250 
62  +   SINE3-1 45  106 590
HISEQ:979:HM2HCBCX2:1:2104:4144:84852 1:N:0:ATCACG  100 161 250 
62  -   SINE3-1 45  106 590
HISEQ:979:HM2HCBCX2:1:1102:2661:55870 1:N:0:ATCACG  141 202 250 
62  +   SINE3-1 45  106 590
HISEQ:979:HM2HCBCX2:1:1110:21298:76907 1:N:0:ATCACG 29  221 250 
193 +   SINE3-1 3   197 590
HISEQ:979:HM2HCBCX2:1:2116:10990:92099 1:N:0:ATCACG 95  151 250 
57  +   SINE3-1 45  101 590
...

carp-carp01_TKD181002053-1_1_sg.txt:
HISEQ:979:HM2HCBCX2:1:1115:9907:8048 1:N:0:ATCACG   117 243 250 
127 +   SINE3-1a210 335 570
HISEQ:979:HM2HCBCX2:1:2208:4628:64650 1:N:0:ATCACG  5   49  250 
45  -   SINE3-1 45  89  590
HISEQ:979:HM2HCBCX2:1:1212:6335:22852 1:N:0:ATCACG  2   250 250 
249 +   SINE3-1 234 486 590
HISEQ:979:HM2HCBCX2:1:1103:16183:52106 1:N:0:ATCACG 1   250 250 
250 -   SINE3-1a229 474 570
HISEQ:979:HM2HCBCX2:1:2211:8958:6423 1:N:0:ATCACG   1   250 250 
250 -   SINE3-1a117 367 570
HISEQ:979:HM2HCBCX2:1:1113:7857:35762 1:N:0:ATCACG  1   152 250 
152 -   SINE3-1 291 445 590
HISEQ:979:HM2HCBCX2:1:1206:12438:18002 1:N:0:ATCACG 1   249 250 
249 -   SINE3-1a283 519 570
...

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;


Sincerely

Dong Liu











--

湖南师范大学生命科学院:刘 东
 
格言:积土而为山,积水而为海;
知识在于积累,成功在于勤奋。

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: perl script question

2019-10-10 Thread Ken Slater
In addition to the comments made by David, it appears the line:

open FASEQ, "<", $files or die "can not read open $!";

is not needed. The file handle FASEQ is never used in an input operation.
You want to use the file name as noted by David.

Ken


On Thu, Oct 10, 2019 at 4:06 AM 刘东  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;
>
> when I run the script, and the results is "FASEQ can not open".
> additional, the results from glob as follows:
> ./fadata//carp-carp01_TKD181002053-1_1.fa
> ./fadata//carp-carp01_TKD181002053-1_2.fa
> ..
>
>
>
>
>
> --
> 湖南师范大学生命科学院:刘 东
>
> *格言:*积土而为山,积水而为海;
> 知识在于积累,成功在于勤奋。
>
>
>
>


Re: perl script question

2019-10-10 Thread David Precious


The error message "FASEQ can not open" doesn't look like something
which could be output by the code you've provided.

*Either* you should get the "can not read open $!" message (where the
$! will be interpolated to the reason it failed), or the message is
coming from whatever the "usearch" tool you're executing is.

Have your script print out the ./usearch invocation instead of running
it, then try running it yourself - if you get the same error then you
at least know that it's not coming from your script.

My guess - did you mean "-ublast FASEQ" to be replaced by the name of
the file you're reading - e.g. "-ublast $files" ? 

Likewise, the "-userout OUTFILE" part of the usearch invocation looks
like you may have intended that to be the output filename, e.g.
"-userout $filename.txt" or similar?

(Incidentally, the var name $files when it holds the singular filename
for each iteration irks me - that'd read much better as e.g.:

for my $filename (glob("$dir/*.fa")) {
...
}


On Thu, 10 Oct 2019 10:21:45 +0800 (CST) 刘东 
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;
> 
> 
> 
> when I run the script, and the results is "FASEQ can not open".
> additional, the results from glob as follows:
> ./fadata//carp-carp01_TKD181002053-1_1.fa
> ./fadata//carp-carp01_TKD181002053-1_2.fa
> ..
> 
> 
> 
> 
> 
> 
> 
> --
> 
> 湖南师范大学生命科学院:刘 东
>  
> 格言:积土而为山,积水而为海;
> 知识在于积累,成功在于勤奋。

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




perl script question

2019-10-10 Thread 刘东
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;



when I run the script, and the results is "FASEQ can not open".
additional, the results from glob as follows:
./fadata//carp-carp01_TKD181002053-1_1.fa
./fadata//carp-carp01_TKD181002053-1_2.fa
..







--

湖南师范大学生命科学院:刘 东
 
格言:积土而为山,积水而为海;
知识在于积累,成功在于勤奋。

Re: Question re remove_tree and symlinks

2019-08-24 Thread David Precious
On Fri, 23 Aug 2019 19:13:15 +0100
Mike Martin  wrote:

> Am I right in believing that remove_tree from File::Path does not
> follow symlinks, ie: does not remove the linked file only the link if
> there are links in the direstories removed

An obvious way to find out would be to just try it - set up two test
directories with files, add a symlink in the first to a file in the
second, then run remove_tree on the first and see what happens :)

Otherwise, File::Path uses unlink() to remove the files, the doco for
which is at https://perldoc.perl.org/functions/unlink.html

That isn't massively detailed, but the manpage for unlink(2) gives much
more detail: https://linux.die.net/man/2/unlink

-- start quote --
unlink() deletes a name from the file system. If that name was the
last link to a file and no processes have the file open the file is
deleted and the space it was using is made available for reuse.

If the name was the last link to a file but any processes still have
the file open the file will remain in existence until the last file
descriptor referring to it is closed.

If the name referred to a symbolic link the link is removed. 
-- end quote --


So, if there's a symlink, you can expect the symlink to be removed, but
the file it linked to to be untouched.  Even if it's a hard link, the
file will still exist unless the other link to it gets removed.

Cheers

Dave P (BIGPRESH)

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




Question re remove_tree and symlinks

2019-08-23 Thread Mike Martin
Am I right in believing that remove_tree from File::Path does not follow
symlinks, ie: does not remove the linked file only the link if there are
links in the direstories removed

eg:
#!/usr/bin/perl
use strict;
use File::Path('make_path','remove_tree');
my $dir='testdellink';# contains links to files in testdel
remove_tree($dir,{safe => 1});

Will not remove files in testdel that are linked to in testdellink

thanks

Mike


AI::PredictionClient question

2019-08-08 Thread Eliza

Hello,

Is this module still be maintained actively?
https://metacpan.org/pod/AI::PredictionClient

I saw the last version was released on 2017.

And there is the Inception client sample there, if I want to request a 
different CNN model, how to build the client?


thanks & regards,
Eliza C.

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




Re: stupid question about to protect source code of perl web application scripting

2019-07-09 Thread Kent Fredric
On Mon, 8 Jul 2019 at 13:45, Eko Budiharto  wrote:
>
> dear all,
>
> first of all, thank you for the respond of my inquiry. And then, there
> is a few questions I would like to ask:
>
> 1. if someone takes your works and then he steals the credit by claiming
> the work is his work instead of your work, what will you do?


1. Check the relevant licenses or contracts you issued your code under.
2. If they are in contravention of these, threaten them with a lawsuit .
3. If possible, follow through with lawsuit

> 2. if someone has a problem, he does not want to try to find a way to
> solve the problem first, and then he asks your help and then problem
> solved, then he is blaming the person who already helped him and
> claimed, that is his work. what will you do?

1. Refuse to offer them future support

Understandably, both of these situations are not nice to be in.
However, the hard reality is you *cannot* protect code from
unscrupulous agents who you've given it to beyond legal manners.

No more than you can prevent somebody from modifying a vehicle you sold them.

You can make it more difficult, and you can perform various legal
moves (Copyright law, Trademark violations, Patent Law) to
deter/restrict it, but you cannot prevent the act.

Take the humble padlock. If you think you can make a 100% secure
padlock, you're kidding yourself. There's a collection of youtube
channels of people defeating these in various ways, some of them are
defeated in *comically* short time. I doubt there are many, if any,
that are completely immune to attack.

The time and money invested in these are frequently a total waste.

They only serve as a *deterrent* against all but the most persistent attacker.

Because "The lock is only as good as the thief is honest".

Sure, it does make sense to have some sort of arbitrary deterrent, but
what will _you_ do after you spend all this time investing in said
deterrent, and your user trivially defeats it on day 1 *anyway*?

Its not like you leave your house unlocked, but ultimately, if the
lock is broken, what will you do then?

If your lock is defeated and your stuff is stolen, that's when you
call up the legal system.

Software is not a whole bunch different.

The only way to completely secure something against a user meddling
with it against your wishes, is simply to put it in a place they can't
execute *any* attacks.

As then, they have to violate your physical security to contravene the software.

( What are you going to do if an aggrieved user bashes down the door
to your server cabinet and steals your hard drive? You'll call the
police. Software isn't exactly going to save you here. But it might
help you if your hard drives are encrypted. But you're still gonna
need to call the police )

-- 
Kent

KENTNL - https://metacpan.org/author/KENTNL

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




Re: stupid question about to protect source code of perl web application scripting

2019-07-08 Thread Shlomi Fish
On Mon, 8 Jul 2019 15:07:41 +0700
Eko Budiharto  wrote:

> >> 2. if someone has a problem, he does not want to try to find a way to
> >> solve the problem first, and then he asks your help and then problem
> >> solved, then he is blaming the person who already helped him and
> >> claimed, that is his work. what will you do?
> >>  
> > What do you mean?
> >
> >  
> dear Shlomi,
> 
> what I mean in this one is the person has a problem, but he does not 
> make any efforts first, he just ask the solution from someone else. 
> After the problem is solved, he blames the person.
> 
> For example:
> 
> I have a problem and then I do not do anything or make my own effort and 
> then I ask your help to solve it for me. After the problem solved 
> because you helped me, I blame you instead you being grateful and thank 
> you and plus I said to anyone that I am the one who solved if instead of 
> your name.
> 

I understand now, thanks. That seems like a very ungrateful and "bastard"y
thing to do. I won't like it, but not sure how i'll act.

-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://youtu.be/xZLwtc9x4yA - Anime in Real Life!! (Parody)

An apple a day keeps the doctor away.
Two apples a day will keep two doctors away.
— one of Shlomi Fish’s relatives

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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




Re: stupid question about to protect source code of perl web application scripting

2019-07-08 Thread Eko Budiharto




2. if someone has a problem, he does not want to try to find a way to
solve the problem first, and then he asks your help and then problem
solved, then he is blaming the person who already helped him and
claimed, that is his work. what will you do?


What do you mean?



dear Shlomi,

what I mean in this one is the person has a problem, but he does not 
make any efforts first, he just ask the solution from someone else. 
After the problem is solved, he blames the person.


For example:

I have a problem and then I do not do anything or make my own effort and 
then I ask your help to solve it for me. After the problem solved 
because you helped me, I blame you instead you being grateful and thank 
you and plus I said to anyone that I am the one who solved if instead of 
your name.


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




Re: stupid question about to protect source code of perl web application scripting

2019-07-08 Thread Shlomi Fish
Hi,

On Mon, 8 Jul 2019 08:44:46 +0700
Eko Budiharto  wrote:

> dear all,
> 
> first of all, thank you for the respond of my inquiry. And then, there 
> is a few questions I would like to ask:
> 
> 1. if someone takes your works and then he steals the credit by claiming 
> the work is his work instead of your work, what will you do?
> 

First note that it never happened to me.

Anyway, in this case, I will try to find evidence that I originated the works
first, e.g:

* https://en.wikipedia.org/wiki/Wayback_Machine

* https://en.wikipedia.org/wiki/Version_control histories

* https://en.wikipedia.org/wiki/Internet_forum archives

Note that I think the most restrictive licences I used are
https://en.wikipedia.org/w/index.php?title=CC-by-nc-sa&redirect=no and
https://en.wikipedia.org/wiki/Affero_General_Public_License which also allow
asserting copyright on derivative changes.

If the person who claims my work is theirs does not sue me for infringement, I
will likely not care much:

* https://fc-solve.shlomifish.org/faq.html#abuse_of_fc_solve

* https://www.mail-archive.com/linux-il@cs.huji.ac.il/msg56378.html

> 2. if someone has a problem, he does not want to try to find a way to 
> solve the problem first, and then he asks your help and then problem 
> solved, then he is blaming the person who already helped him and 
> claimed, that is his work. what will you do?
> 

What do you mean?

> This is kind of some images of this dishonest person.
> 
> I do not mind to share my code to the person, if he does not have that 
> character.
> 
> So far, I am using the perl code for web application in a hosting 
> server. But this time, I have to create a web application on a on 
> premise server.
> 
> I am not an expert yet in perl and still learning although I know perl 
> when I got still in my university 19 years ago.
> 
> regards,
> 
> Eko Budiharto
> 
> 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

Do you always begin conversations this way?
— https://en.wikipedia.org/wiki/The_Princess_Bride_%28film%29

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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




Re: stupid question about to protect source code of perl web application scripting

2019-07-07 Thread Eko Budiharto

dear all,

first of all, thank you for the respond of my inquiry. And then, there 
is a few questions I would like to ask:


1. if someone takes your works and then he steals the credit by claiming 
the work is his work instead of your work, what will you do?


2. if someone has a problem, he does not want to try to find a way to 
solve the problem first, and then he asks your help and then problem 
solved, then he is blaming the person who already helped him and 
claimed, that is his work. what will you do?


This is kind of some images of this dishonest person.

I do not mind to share my code to the person, if he does not have that 
character.


So far, I am using the perl code for web application in a hosting 
server. But this time, I have to create a web application on a on 
premise server.


I am not an expert yet in perl and still learning although I know perl 
when I got still in my university 19 years ago.


regards,

Eko Budiharto


On 07/07/19 14.54, Kent Fredric wrote:

On 7/6/19 11:21 PM, Eko Budiharto wrote:

it is a web application but it is on premise. The user is not honest.
That's why I am trying to find a way to protect the source code like
in java we can compile into java class and still can be run.

That's a false sense of securtiy. A sufficiently "dishonest" person
can decompile your class files back into source.

It may not be the original source, comments may be lost, function
names and variables may become nonsensical, ( but this last part
typically requires additional obfuscation beyond the standard java
compiler )

But the logic, the interface, and all the metadata required to make
backtraces remotely comprehensible, is all still there for anyone who
wants to look.


I read some articles in the internet. Some method are using PAR,
perlc, Filter::Crypto, acme::bleach, but I am not sure it will encrypt
the source code and it still can be runnable.

Perl is basically the same, you can make it harder for the laziest of
people to obtain readable source code, but ultimately, all these
systems are obfuscation, _not_ protection, they all internally decode
the code first before handing it over to the perl interpreter, as
that's the only way to get it to execute. All an enterprising person
has to do is put some glue between that decoder and the perl runtime,
and the code reveals itself. Or ... you simply need to have that
decoded stuff loaded in memory, and then point deparse at the
in-memory function, and it will spit out something that looks a lot
like the original code.

In short, the time invested in this aspect will basically cost you
money, without materially giving you anything for it. And worse, it
increases the odds that your code will randomly stop working,
frustrating your user, making them swear to never do business with you
again, _AND_ then forcing them to attempt to break your "protection"
in order to fix their broken code.

Just don't bother.

Either simply place the software on a platform where they have no
access to any form of the code whatsoever, not even in its executable
state ( as Uri says ), or put an Iron Clad contract on it that
empowers you to sue the pants off them if they do anything you don't
like with it.

Spend your time working on making a great product that works and makes
them happy so they never *need* to reverse-engineer it, so they never
*need* to compete with you, and you'll have a customer for life.

Don't waste time and money on misguided attempts at "protecting your
code" which will only make you enemies and give your competition the
advantage.

( This stupidity has been tried ad-infinitum in everything, and entire
websites now exist for the sole purpose of distributing defeat
mechanisms, and distributing defeated copies of the software. Its an
arms race, one you will ultimately lose. )



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




Re: stupid question about to protect source code of perl web application scripting

2019-07-07 Thread Shlomi Fish
Hi all,

On Sun, 7 Jul 2019 19:54:30 +1200
Kent Fredric  wrote:

> > On 7/6/19 11:21 PM, Eko Budiharto wrote:  
> > > it is a web application but it is on premise. The user is not honest.
> > > That's why I am trying to find a way to protect the source code like
> > > in java we can compile into java class and still can be run.  
> 
> That's a false sense of securtiy. A sufficiently "dishonest" person
> can decompile your class files back into source.
> 
> It may not be the original source, comments may be lost, function
> names and variables may become nonsensical, ( but this last part
> typically requires additional obfuscation beyond the standard java
> compiler )
> 
> But the logic, the interface, and all the metadata required to make
> backtraces remotely comprehensible, is all still there for anyone who
> wants to look.
> 

In addition see these FAQ replies:

*
https://perl-begin.org/FAQs/freenode-perl/#How_can_I_compile_my_code_to_obscure_.2F_obfuscate_the_source.3F

*
https://github.com/shlomif/Freenode-programming-channel-FAQ/blob/master/FAQ_with_ToC__generated.md#how-do-i-hideobscureencrypt-my-source-code-to-prevent-end-users-from-learning-how-it-works

This question is very old...


-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/bits/facts/Summer-Glau/

Cogito cogito ergo cogito sum --
"I think that I think, therefore I think that I am."
— Ambrose Bierce, "The Devil's Dictionary"

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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




Re: stupid question about to protect source code of perl web application scripting

2019-07-07 Thread Kent Fredric
> On 7/6/19 11:21 PM, Eko Budiharto wrote:
> > it is a web application but it is on premise. The user is not honest.
> > That's why I am trying to find a way to protect the source code like
> > in java we can compile into java class and still can be run.

That's a false sense of securtiy. A sufficiently "dishonest" person
can decompile your class files back into source.

It may not be the original source, comments may be lost, function
names and variables may become nonsensical, ( but this last part
typically requires additional obfuscation beyond the standard java
compiler )

But the logic, the interface, and all the metadata required to make
backtraces remotely comprehensible, is all still there for anyone who
wants to look.

> >
> > I read some articles in the internet. Some method are using PAR,
> > perlc, Filter::Crypto, acme::bleach, but I am not sure it will encrypt
> > the source code and it still can be runnable.

Perl is basically the same, you can make it harder for the laziest of
people to obtain readable source code, but ultimately, all these
systems are obfuscation, _not_ protection, they all internally decode
the code first before handing it over to the perl interpreter, as
that's the only way to get it to execute. All an enterprising person
has to do is put some glue between that decoder and the perl runtime,
and the code reveals itself. Or ... you simply need to have that
decoded stuff loaded in memory, and then point deparse at the
in-memory function, and it will spit out something that looks a lot
like the original code.

In short, the time invested in this aspect will basically cost you
money, without materially giving you anything for it. And worse, it
increases the odds that your code will randomly stop working,
frustrating your user, making them swear to never do business with you
again, _AND_ then forcing them to attempt to break your "protection"
in order to fix their broken code.

Just don't bother.

Either simply place the software on a platform where they have no
access to any form of the code whatsoever, not even in its executable
state ( as Uri says ), or put an Iron Clad contract on it that
empowers you to sue the pants off them if they do anything you don't
like with it.

Spend your time working on making a great product that works and makes
them happy so they never *need* to reverse-engineer it, so they never
*need* to compete with you, and you'll have a customer for life.

Don't waste time and money on misguided attempts at "protecting your
code" which will only make you enemies and give your competition the
advantage.

( This stupidity has been tried ad-infinitum in everything, and entire
websites now exist for the sole purpose of distributing defeat
mechanisms, and distributing defeated copies of the software. Its an
arms race, one you will ultimately lose. )

-- 
Kent

KENTNL - https://metacpan.org/author/KENTNL

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




Re: stupid question about to protect source code of perl web application scripting

2019-07-06 Thread Uri Guttman

On 7/6/19 11:21 PM, Eko Budiharto wrote:

dear Uri,

it is a web application but it is on premise. The user is not honest. 
That's why I am trying to find a way to protect the source code like 
in java we can compile into java class and still can be run.


I read some articles in the internet. Some method are using PAR, 
perlc, Filter::Crypto, acme::bleach, but I am not sure it will encrypt 
the source code and it still can be runnable.


The application users of course cannot read the source code, but the 
sys admin can access the source code and this sys admin is a dishonest 
person. :)




the whole point of those methods is to 'hide' the code and keep it 
runnable. you can try them out and see that they will keep the code 
runnable. how well they 'hide' the code is a different story.


again, i am asking why this code is so valuable (and you are a new perl 
coder it seems) that hiding it is so important.


you can easily get access to a different server away from this dishonest 
admin and redirect your local script to the other place. since the admin 
won't have access to the other server, it will be safe from viewing.


if this is so valuable, paying $5/month for a basic hosting service 
would be worth your while.


uri

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




Re: stupid question about to protect source code of perl web application scripting

2019-07-06 Thread Eko Budiharto

dear Uri,

it is a web application but it is on premise. The user is not honest. 
That's why I am trying to find a way to protect the source code like in 
java we can compile into java class and still can be run.


I read some articles in the internet. Some method are using PAR, perlc, 
Filter::Crypto, acme::bleach, but I am not sure it will encrypt the 
source code and it still can be runnable.


The application users of course cannot read the source code, but the sys 
admin can access the source code and this sys admin is a dishonest 
person. :)



On 07/07/19 10.08, Uri Guttman wrote:

On 7/6/19 11:01 PM, Eko Budiharto wrote:

dear all,

I have a question. I have written a web application with perl, 
unfortunately everything written in perl, everyone can see all source 
codes I wrote. My question is is there anyway to protect those source 
codes? Compile or encrypt it?




if it is a web application and you don't give out the source, it 
should be inaccessible to users of the application. but in general 
there is no secure way to hide perl source if you want to distribute 
the program. if your application is worth something, then honest users 
will pay for it and you shouldn't need to hide the source.


uri



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




Re: stupid question about to protect source code of perl web application scripting

2019-07-06 Thread Uri Guttman

On 7/6/19 11:10 PM, Eko Budiharto wrote:

dear Uri,

it is a web application but it is on premise. The user is not honest. 
That's why I am trying to find a way to protect the source code like 
in java we can compile into java class and still can be run.


please write to the list and not only to me. use a wide reply for that. 
i cc'ed the list.


i am not sure what you mean by "on premise". what did you write that has 
a dishonest user accessing it? there are ways to hide perl code but they 
are all breakable with some skill needed. if your user isn't skilled or 
doesn't want to get into the source, try one of those methods. you can 
google around and find them.


but it would be better to write the code so that even a dishonest user 
can't break in behind the code. the source code can be useless to them 
if it accesses secure resources (e.g. a database or other server) with a 
login/password that is not in the code.


uri

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




Re: stupid question about to protect source code of perl web application scripting

2019-07-06 Thread Uri Guttman

On 7/6/19 11:01 PM, Eko Budiharto wrote:

dear all,

I have a question. I have written a web application with perl, 
unfortunately everything written in perl, everyone can see all source 
codes I wrote. My question is is there anyway to protect those source 
codes? Compile or encrypt it?




if it is a web application and you don't give out the source, it should 
be inaccessible to users of the application. but in general there is no 
secure way to hide perl source if you want to distribute the program. if 
your application is worth something, then honest users will pay for it 
and you shouldn't need to hide the source.


uri

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




stupid question about to protect source code of perl web application scripting

2019-07-06 Thread Eko Budiharto

dear all,

I have a question. I have written a web application with perl, 
unfortunately everything written in perl, everyone can see all source 
codes I wrote. My question is is there anyway to protect those source 
codes? Compile or encrypt it?



I am looking forward to a favorable reply from you. Thank you.


regards,

Eko

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




Re: newbie question for parsing incoming mails

2017-02-16 Thread Jim Gibson

> On Feb 15, 2017, at 9:56 PM, Eko Budiharto  wrote:
> 
> Jim,
> I have one a couple more questions.
> -. For the header, what if, I just need the subject, the from, and the 
> recipient, what is the command? I read the manual in the 
> https://metacpan.org/pod/Email::MIME#header, it does not tell me how to 
> extract all of those.
> -. And then, for the email contents of the body, it just shows Content-Type: 
> multipart/alternative; boundary=f403045de9521d20cc054874ce1a 
> instead of the contents of the email body. How to extract it into string 
> because it is under html format.

Please post all questions to the list. There are other people who can answer 
your questions better than I can.

I just parse the text of the email using regular expressions, line by line:

my @lines = split(/[\n\r]+/,$text);

for( my $i = 0; $i <= $#lines; $i++ ) {
my $line = $lines[$i];
print "$i. $line\n" if $xdebug;

if( $line =~ m{ \A Subject:\ (.*) \z }x ) {
$subject = $1;

etc.

You can also try to use the Email::MIME::header method:

my $from = $mime->header(‘From’):

I haven’t used that, but it might be worth trying. Email::MIME is an extension 
of the Email::Simple class, so you can look at the documentation for that 
module as well. 
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie question for parsing incoming mails

2017-02-15 Thread Eko Budiharto
dear all,
I have one a couple questions.
-. For the header, what if, I just need the subject, the from, and the 
recipient, what is the command? I read the manual in the 
https://metacpan.org/pod/Email::MIME#header 
, it does not tell me how to 
extract all of those.
-. And then, for the email contents of the body, it just shows Content-Type: 
multipart/alternative; boundary=f403045de9521d20cc054874ce1a 
instead of the contents of the email body. How to extract it into string 
because it is under html format.

> On Feb 16, 2017, at 11:45, Jim Gibson  wrote:
> 
> 
>> On Feb 15, 2017, at 8:10 PM, Eko Budiharto  wrote:
>> 
>> dear Jim,
>> I tried to add lines to read file like this:
>> 
>> use Email::MIME;
>> 
>> my $file = '/var/qmail/mailnames/> name>/support/Maildir/cur/1487041394.M984019P23084V0803I00E03878.ABCD.NET,S=3987:2,';
>> open my $ifh, '<', $file
>>  or die "Cannot open '$file' for reading: $!";
>> local $/ = '';
>> my $contents = <$ifh>;
>> close( $ifh );
>> 
>> my $mime = Email::MIME->($contents);  —> line 13
>> 
>> my @parts = $mime->parts();
>> 
>> for my $npart ( 0..$#parts ) {
>>  my $part = $parts[$npart];
>>  my $header = $part->header_obj();
>>  my $htext = $header->as_string();
>>  my $body = $part->body();
>> 
>>  print $header;
>> }
>> 
>> after I ran its from CLI, I got an error message Undefined subroutine 
>> &Email::MIME called at line 13.
>> 
>> what does the error mean?
> 
> That means I mistyped the line. It should be this:
> 
>   my $mime = Email::MIME->new($contents);
> 
> 



Re: newbie question for parsing incoming mails

2017-02-15 Thread Jim Gibson
On Feb 15, 2017, at 7:10 PM, Eko Budiharto  wrote:
> 
> Jim, 
> if I want to extract all incoming emails from my qmail emails, how can 
> specify the folder location and specify the file name since the file name 
> always different?
> 
> Thx.

Use File::Find or opendir and readdir to find all of the emails in a directory 
tree. You need to figure out the parent directory, if there is one, of the 
local storage for your email client.

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




Re: newbie question for parsing incoming mails

2017-02-15 Thread Jim Gibson

> On Feb 15, 2017, at 8:10 PM, Eko Budiharto  wrote:
> 
> dear Jim,
> I tried to add lines to read file like this:
> 
> use Email::MIME;
> 
> my $file = '/var/qmail/mailnames/ name>/support/Maildir/cur/1487041394.M984019P23084V0803I00E03878.ABCD.NET,S=3987:2,';
> open my $ifh, '<', $file
>   or die "Cannot open '$file' for reading: $!";
> local $/ = '';
> my $contents = <$ifh>;
> close( $ifh );
> 
> my $mime = Email::MIME->($contents);  —> line 13
> 
> my @parts = $mime->parts();
> 
> for my $npart ( 0..$#parts ) {
>   my $part = $parts[$npart];
>   my $header = $part->header_obj();
>   my $htext = $header->as_string();
>   my $body = $part->body();
> 
>   print $header;
> }
> 
> after I ran its from CLI, I got an error message Undefined subroutine 
> &Email::MIME called at line 13.
> 
> what does the error mean?

That means I mistyped the line. It should be this:

my $mime = Email::MIME->new($contents);

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




Re: newbie question for parsing incoming mails

2017-02-15 Thread Eko Budiharto
dear Jim,
I tried to add lines to read file like this:

use Email::MIME;

my $file = '/var/qmail/mailnames//support/Maildir/cur/1487041394.M984019P23084V0803I00E03878.ABCD.NET,S=3987:2,';
open my $ifh, '<', $file
  or die "Cannot open '$file' for reading: $!";
local $/ = '';
my $contents = <$ifh>;
close( $ifh );

my $mime = Email::MIME->($contents);  —> line 13

my @parts = $mime->parts();

for my $npart ( 0..$#parts ) {
  my $part = $parts[$npart];
  my $header = $part->header_obj();
  my $htext = $header->as_string();
  my $body = $part->body();

  print $header;
}

after I ran its from CLI, I got an error message Undefined subroutine 
&Email::MIME called at line 13.

what does the error mean?



> On Feb 15, 2017, at 22:56, Jim Gibson  wrote:
> 
> I use Email::MIME to parse email messages. After reading the email file into 
> the variable $text I do this:
> 
> my $mime = Email::MIME->($text);
> my @parts = $mime->parts();
> 
> for my $npart ( 0..$#parts ) {
>  my $part = $parts[$npart];
>  my $header = $part->header_obj();
>  my $htext = $header->as_string();
>  my $body = $part->body();
>  …
> }
> 
> 
> 
> 
> 
> Jim Gibson



Re: newbie question for parsing incoming mails

2017-02-15 Thread Eko Budiharto
Jim, 
if I want to extract all incoming emails from my qmail emails, how can specify 
the folder location and specify the file name since the file name always 
different?

Thx.
> On Feb 15, 2017, at 22:56, Jim Gibson  wrote:
> 
>> 
>> On Feb 14, 2017, at 10:38 PM, Eko Budiharto  wrote:
>> 
>> dear all,
>> I have a question. 
>> If I would like to parse all incoming mails from my qmail, which perl module 
>> is easy to use?
>> my qmail emails incoming is /var/qmail/mailnames//support. In 
>> this folder I already have preline in .qmail for piping emails to my perl 
>> script.
>> And, my perl script what I already have is like this:
>> 
>> #!/usr/bin/perl -w
>> 
>> use Mail::Internet;
>> 
>> my $mail = Mail::Internet->new( [  ] );
>> my $headers = $mail->head->header_hashref;
>> my @subject = @{${$headers}{'Subject'}}; # or otherwsie do it in list 
>> context it works
>> 
>> print @subject;
>> 
>> 
>> when I run it, I do not get anything.
>> 
>> please help.
> 
> I use Email::MIME to parse email messages. After reading the email file into 
> the variable $text I do this:
> 
> my $mime = Email::MIME->($text);
> my @parts = $mime->parts();
> 
> for my $npart ( 0..$#parts ) {
>  my $part = $parts[$npart];
>  my $header = $part->header_obj();
>  my $htext = $header->as_string();
>  my $body = $part->body();
>  …
> }
> 
> 
> 
> 
> 
> Jim Gibson



Re: newbie question for parsing incoming mails

2017-02-15 Thread Andy Bach
> when I run it, I do not get anything.
Hmm, how are you testing it. I put a single header and msg in /tmp/ml.txt
(Subject: training.error Trouble wiwb) and:
$ parse_email_simple.pl < /tmp/ml.txt
training.error Trouble wiwb (8 lines)
$ cat /tmp/ml.txt | parse_email_simple.pl
training.error Trouble wiwb (8 lines)

In addition, if I take out STDOUT
my $mail = Mail::Internet->new( [ <> ] );

I can do:
$ parse_email_simple.pl  /tmp/ml.txt

as Perl'll open the command line file name argument

Note, these'll treat all input as a single msg.

On Wed, Feb 15, 2017 at 12:38 AM, Eko Budiharto 
wrote:

> dear all,
> I have a question.
> If I would like to parse all incoming mails from my qmail, which perl
> module is easy to use?
> my qmail emails incoming is /var/qmail/mailnames//support.
> In this folder I already have preline in .qmail for piping emails to my
> perl script.
> And, my perl script what I already have is like this:
>
> #!/usr/bin/perl -w
>
> use Mail::Internet;
>
> my $mail = Mail::Internet->new( [  ] );
> my $headers = $mail->head->header_hashref;
> my @subject = @{${$headers}{'Subject'}}; # or otherwsie do it in list
> context it works
>
> print @subject;
>
>
> when I run it, I do not get anything.
>
> please help.
>
> regards,
> Eko
>



-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: newbie question for parsing incoming mails

2017-02-15 Thread Jim Gibson

> On Feb 14, 2017, at 10:38 PM, Eko Budiharto  wrote:
> 
> dear all,
> I have a question. 
> If I would like to parse all incoming mails from my qmail, which perl module 
> is easy to use?
> my qmail emails incoming is /var/qmail/mailnames//support. In 
> this folder I already have preline in .qmail for piping emails to my perl 
> script.
> And, my perl script what I already have is like this:
>  
> #!/usr/bin/perl -w
>  
> use Mail::Internet;
> 
> my $mail = Mail::Internet->new( [  ] );
> my $headers = $mail->head->header_hashref;
> my @subject = @{${$headers}{'Subject'}}; # or otherwsie do it in list context 
> it works
> 
> print @subject;
> 
> 
> when I run it, I do not get anything.
> 
> please help.

I use Email::MIME to parse email messages. After reading the email file into 
the variable $text I do this:

my $mime = Email::MIME->($text);
my @parts = $mime->parts();

for my $npart ( 0..$#parts ) {
  my $part = $parts[$npart];
  my $header = $part->header_obj();
  my $htext = $header->as_string();
  my $body = $part->body();
  …
}





Jim Gibson

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




newbie question for parsing incoming mails

2017-02-14 Thread Eko Budiharto
dear all,
I have a question.
If I would like to parse all incoming mails from my qmail, which perl
module is easy to use?
my qmail emails incoming is /var/qmail/mailnames//support. In
this folder I already have preline in .qmail for piping emails to my perl
script.
And, my perl script what I already have is like this:

#!/usr/bin/perl -w

use Mail::Internet;

my $mail = Mail::Internet->new( [  ] );
my $headers = $mail->head->header_hashref;
my @subject = @{${$headers}{'Subject'}}; # or otherwsie do it in list
context it works

print @subject;


when I run it, I do not get anything.

please help.

regards,
Eko


Re: FW: Question about Beginning Perl by Simon Cozens

2016-09-01 Thread Neil Hainer
Mike,

Do what's best for you and enjoy Simon's Cozens book.  I always liked the
way he wrote as well.

On Thu, Sep 1, 2016 at 1:49 PM, Walker, Michael E <
michael.e.walk...@boeing.com> wrote:

>
>
>
>
> *From:* Walker, Michael E
> *Sent:* Thursday, September 01, 2016 12:47 PM
> *To:* 'Aaron Wells'
> *Subject:* RE: Question about Beginning Perl by Simon Cozens
>
>
>
> Thank you all for sharing your perspective on this. I will compare both
> the first and second editions of *Beginning Perl*. Cozens’ writing style
> really resonates with me, because of the problem-solving approach he takes
> when introducing each Perl concept. For example, even though the book is
> outdated in some respects, I appreciated his examples on using the while
> loop to create a number guessing game, and as the book progressed, I saw
> something in there about computing a Taylor series. I believe I also saw a
> Fibonacci series. I also like how he describes file processing in depth.
> This contrasts with a lot of books I have seen where instead of
> problem-solving, it seems that simple examples are introduced, to
> demonstrate each language feature.
>
>
>
> Mike
>
>
>
> *From:* Aaron Wells [mailto:chacewe...@gmail.com ]
> *Sent:* Thursday, September 01, 2016 12:06 PM
> *To:* Walker, Michael E
> *Subject:* Re: Question about Beginning Perl by Simon Cozens
>
>
>
> Edit: s/done/fine/
>
>
>
> On Thu, Sep 1, 2016, 10:04 AM Aaron Wells  wrote:
>
> Because Perl 5 has been committed to backward compatibility, I think
> beginning Perl is still a good reference for learning the Perl
> fundamentals. You'll learn the main concepts that make Perl Perl. And as
> with all things, it depends on what you're up to. If you're doing systems
> administration or automating things, sticking with that level is done.
> Application development is a different story though. "Modern Perl" will get
> you up to speed with the tools and techniques application developers are
> using to get application up and running faster with fewer bugs.
>
>
>
> On Thu, Sep 1, 2016, 9:53 AM Walker, Michael E <
> michael.e.walk...@boeing.com> wrote:
>
> Hi, even though *Beginning Perl* dates back to 2000, is it still relevant
> for learning today? I wondered, because when Googling, I saw posts
> recommending against its use, but yet it is still listed at books.perl.org.
> Please discuss, or point me to the archive on this list where this has been
> discussed. Thank you.
>
>


Re: Question about Beginning Perl by Simon Cozens

2016-09-01 Thread Neil Hainer
I agree about starting with Learning Perl.  It so happens that a new
edition is about to become available.  The following URL is from The
Learning Perl website:

https://www.learning-perl.com/2016/08/pre-order-learning-perl-7th-edition/



On Thu, Sep 1, 2016 at 1:03 PM, Hao Wu  wrote:

> https://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840
>
> This one is more relevant. I read it and it is very good.
>
> However, If you never programming before Learning Perl probably is better
> to start with.
>
>
>
> On Thu, Sep 1, 2016 at 9:52 AM, Walker, Michael E <
> michael.e.walk...@boeing.com> wrote:
>
>> Hi, even though *Beginning Perl* dates back to 2000, is it still
>> relevant for learning today? I wondered, because when Googling, I saw posts
>> recommending against its use, but yet it is still listed at
>> books.perl.org. Please discuss, or point me to the archive on this list
>> where this has been discussed. Thank you.
>>
>
>


FW: Question about Beginning Perl by Simon Cozens

2016-09-01 Thread Walker, Michael E


From: Walker, Michael E
Sent: Thursday, September 01, 2016 12:47 PM
To: 'Aaron Wells'
Subject: RE: Question about Beginning Perl by Simon Cozens

Thank you all for sharing your perspective on this. I will compare both the 
first and second editions of Beginning Perl. Cozens’ writing style really 
resonates with me, because of the problem-solving approach he takes when 
introducing each Perl concept. For example, even though the book is outdated in 
some respects, I appreciated his examples on using the while loop to create a 
number guessing game, and as the book progressed, I saw something in there 
about computing a Taylor series. I believe I also saw a Fibonacci series. I 
also like how he describes file processing in depth. This contrasts with a lot 
of books I have seen where instead of problem-solving, it seems that simple 
examples are introduced, to demonstrate each language feature.

Mike

From: Aaron Wells [mailto:chacewe...@gmail.com]
Sent: Thursday, September 01, 2016 12:06 PM
To: Walker, Michael E
Subject: Re: Question about Beginning Perl by Simon Cozens


Edit: s/done/fine/

On Thu, Sep 1, 2016, 10:04 AM Aaron Wells 
mailto:chacewe...@gmail.com>> wrote:

Because Perl 5 has been committed to backward compatibility, I think beginning 
Perl is still a good reference for learning the Perl fundamentals. You'll learn 
the main concepts that make Perl Perl. And as with all things, it depends on 
what you're up to. If you're doing systems administration or automating things, 
sticking with that level is done. Application development is a different story 
though. "Modern Perl" will get you up to speed with the tools and techniques 
application developers are using to get application up and running faster with 
fewer bugs.

On Thu, Sep 1, 2016, 9:53 AM Walker, Michael E 
mailto:michael.e.walk...@boeing.com>> wrote:
Hi, even though Beginning Perl dates back to 2000, is it still relevant for 
learning today? I wondered, because when Googling, I saw posts recommending 
against its use, but yet it is still listed at 
books.perl.org<http://books.perl.org>. Please discuss, or point me to the 
archive on this list where this has been discussed. Thank you.


Re: Question about Beginning Perl by Simon Cozens

2016-09-01 Thread Илья Рассадин

Hi!

For introduction to Modern Perl practicies, read Modern Perl by chromatic

http://modernperlbooks.com/books/modern_perl_2016/index.html


01.09.16 19:52, Walker, Michael E пишет:


Hi, even though _Beginning Perl_ dates back to 2000, is it still 
relevant for learning today? I wondered, because when Googling, I saw 
posts recommending against its use, but yet it is still listed at 
books.perl.org. Please discuss, or point me to the archive on this 
list where this has been discussed. Thank you.






Re: Question about Beginning Perl by Simon Cozens

2016-09-01 Thread Hao Wu
https://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840

This one is more relevant. I read it and it is very good.

However, If you never programming before Learning Perl probably is better
to start with.



On Thu, Sep 1, 2016 at 9:52 AM, Walker, Michael E <
michael.e.walk...@boeing.com> wrote:

> Hi, even though *Beginning Perl* dates back to 2000, is it still relevant
> for learning today? I wondered, because when Googling, I saw posts
> recommending against its use, but yet it is still listed at books.perl.org.
> Please discuss, or point me to the archive on this list where this has been
> discussed. Thank you.
>


Question about Beginning Perl by Simon Cozens

2016-09-01 Thread Walker, Michael E
Hi, even though Beginning Perl dates back to 2000, is it still relevant for 
learning today? I wondered, because when Googling, I saw posts recommending 
against its use, but yet it is still listed at books.perl.org. Please discuss, 
or point me to the archive on this list where this has been discussed. Thank 
you.


Re: A multi line pattern match question

2016-07-14 Thread Andrew Solomon
Hi Darryl

After all that I must confess that when I'm making config changes to
multiple servers, I use Rex:

http://rexify.org/

https://metacpan.org/pod/Rex

which is something like Puppet-lite:)

Andrew

On Thu, Jul 14, 2016 at 11:04 PM, Darryl Philip Baker <
darryl.ba...@northwestern.edu> wrote:

> I settled for an set of stacked if statements, saving the previous line if
> needed etc...
>
> Thanks for the help.
>
> Darryl Baker
> PMOET -DAPS
> X76674
>



-- 
Andrew Solomon

Mentor@Geekuni http://geekuni.com/
http://www.linkedin.com/in/asolomon


RE: A multi line pattern match question

2016-07-14 Thread Darryl Philip Baker
I settled for an set of stacked if statements, saving the previous line if 
needed etc... 

Thanks for the help.

Darryl Baker
PMOET -DAPS
X76674


Re: A multi line pattern match question

2016-07-14 Thread Charles DeRykus
One easier approach:

use Tie::File;
tie( my @array, 'Tie::File', "/path/to/file" )
   or die $!;

my $n = 0;
while ( $n <= $#array )  {
  if ( $array[$n] =~ /.*[Oo]rder deny,allow(.*)/  and
$n < $#array and $array[$n+1] =~ /[\Dd]eny from all(.*)/ )
  {
  $n += 2 and print "\tRequire all denied\n";
  next;
  }
  print $array[$n++],"\n";
}



On Thu, Jul 14, 2016 at 7:50 AM, Darryl Philip Baker
 wrote:
> While not truly a beginner it feels that way after not doing anything 
> substantial in Perl in many years.
>
> I currently need a program to take Apache HTTPD configuration files in HTTPD 
> 2.2 syntax used in current production and convert them to HTTPD 2.4 syntax in 
> future production. I will need to do this many times weekly until we cut over 
> to the new systems. My first challenge is converting the permissions syntax:
> Order deny,allow
> Deny from all
> To
> Require all denied
> And similar transformations. I was able to make this modification if I set $/ 
> = undef and look at the file as a whole. My problem is I really want to 
> process the file line by line to remove several  ... 
>  blocks which may have other conditional code blocks contained 
> within them. I have considered using two separate scripts and a two pass 
> solution but there is a part of me which would rather have a single script do 
> it all in one pass.
>
> My current attempt, after several tries, is:
>  if ( m/{.*}[Oo]rder deny,allow(.*)\n(.*)[Dd]eny from all(.*)/) {
> print "\tRequire all denied\n";
> next;
> }
> While not causing syntax errors it is not doing what I want either. I am 
> probably using the 'm/' incorrectly and need your help.
>
> Darryl Baker
>
> --
> 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: A multi line pattern match question

2016-07-14 Thread Omega -1911
On Thu, Jul 14, 2016 at 2:56 PM, Rob McAninch 
wrote:

>
>
> On Thu, Jul 14, 2016 at 1:24 PM, Darryl Philip Baker <
> darryl.ba...@northwestern.edu> wrote:
>
>> On Thu, Jul 14, 2016 at 10:50 AM, Darryl Philip Baker <
>> darryl.ba...@northwestern.edu> wrote:
>>
>> While not truly a beginner it feels that way after not doing anything
>> substantial in Perl in many years.
>>
>>
>>
>> I currently need a program to take Apache HTTPD configuration files in
>> HTTPD 2.2 syntax used in current production and convert them to HTTPD 2.4
>> syntax in future production. I will need to do this many times weekly until
>> we cut over to the new systems. My first challenge is converting the
>> permissions syntax:
>>
>> Order deny,allow
>>
>> Deny from all
>>
>> To
>>
>> Require all denied
>>
>>
>>
>> Why not go line by line? Not 100% certain on the Apache syntax, but in
>> your while loop where you are processing line by line:
>>
>>
>>
>> next if /Order\s+deny,\s*allow/i;  # Skip it in the output
>>
>>
>>
>> if( /(\s*)Deny\s+from\s+all/i) {
>>
>>
>>
>> my $leading_whitespace = $1;  # Preserve whatever whitespace is in
>> the file now, could be multiple tabs and or spaces
>>
>>
>>
>> print $leading_whitespace . "Require all denied";
>>
>>
>>
>> }
>>
>> Learning from that example I came up with:
>>
>> $prevline = $_; # Save current line for
>> later if needed
>>
>> # Change:
>>
>> #   Order deny,all
>>
>> #   Deny from all
>>
>> # To:
>>
>> #   Require all denied
>>
>> # No matter what case the first letters are
>>
>> if ( /Order\s+Deny,\s*Allow/i ) {
>>
>> next;
>>
>> chomp $_;
>>
>> if ( /(\s)Deny\s+from\s+All/i) {
>>
>> $whitespace = $1;
>>
>> print $whitespace, "Require all denied \# New Syntax\n";
>>
>> next;
>>
>> chomp $_;
>>
>> } else {
>>
>> print $prevline, " \# Old Syntax\n";
>>
>> }
>>
>> }
>>
>> It is not doing the expected. The “Order deny,allow” line is never output
>> and where I want “Require all denied” the “Deny from all” is still being
>> output.
>>
>>
>>
> You never get to the nested if. (Not sure why they're nested). When the
> outside if statement is true you immediately call next, that will skip
> everything after it and go back to the nearest loop.
>
> By the way chomp $_ is not necessary as chomp does that when another
> variable is not specified.
>
> In /(\s)Deny\s+from\s+All/ That first \s will match only *one* white
> space character, probably not what you want.
>
> I believe for the Apache syntax to be correct you don't want to output a
> comment on the same line as a statement. Comments in Apache need to be on
> their own line.
>
> 
>


Your comment out Apache syntax and outputting a comment tells me I really
don't need to say much to you but to advise you to execute the code before
replying to the list ;) Comments can be anywhere in an application the
AUTHOR choices to place text with a leading "#".
Have a better day.


Re: A multi line pattern match question

2016-07-14 Thread Rob McAninch
On Thu, Jul 14, 2016 at 1:24 PM, Darryl Philip Baker <
darryl.ba...@northwestern.edu> wrote:

> On Thu, Jul 14, 2016 at 10:50 AM, Darryl Philip Baker <
> darryl.ba...@northwestern.edu> wrote:
>
> While not truly a beginner it feels that way after not doing anything
> substantial in Perl in many years.
>
>
>
> I currently need a program to take Apache HTTPD configuration files in
> HTTPD 2.2 syntax used in current production and convert them to HTTPD 2.4
> syntax in future production. I will need to do this many times weekly until
> we cut over to the new systems. My first challenge is converting the
> permissions syntax:
>
> Order deny,allow
>
> Deny from all
>
> To
>
> Require all denied
>
>
>
> Why not go line by line? Not 100% certain on the Apache syntax, but in
> your while loop where you are processing line by line:
>
>
>
> next if /Order\s+deny,\s*allow/i;  # Skip it in the output
>
>
>
> if( /(\s*)Deny\s+from\s+all/i) {
>
>
>
> my $leading_whitespace = $1;  # Preserve whatever whitespace is in the
> file now, could be multiple tabs and or spaces
>
>
>
> print $leading_whitespace . "Require all denied";
>
>
>
> }
>
> Learning from that example I came up with:
>
> $prevline = $_; # Save current line for
> later if needed
>
> # Change:
>
> #   Order deny,all
>
> #   Deny from all
>
> # To:
>
> #   Require all denied
>
> # No matter what case the first letters are
>
> if ( /Order\s+Deny,\s*Allow/i ) {
>
> next;
>
> chomp $_;
>
> if ( /(\s)Deny\s+from\s+All/i) {
>
> $whitespace = $1;
>
> print $whitespace, "Require all denied \# New Syntax\n";
>
> next;
>
> chomp $_;
>
> } else {
>
> print $prevline, " \# Old Syntax\n";
>
> }
>
> }
>
> It is not doing the expected. The “Order deny,allow” line is never output
> and where I want “Require all denied” the “Deny from all” is still being
> output.
>
>
>
You never get to the nested if. (Not sure why they're nested). When the
outside if statement is true you immediately call next, that will skip
everything after it and go back to the nearest loop.

By the way chomp $_ is not necessary as chomp does that when another
variable is not specified.

In /(\s)Deny\s+from\s+All/ That first \s will match only *one* white space
character, probably not what you want.

I believe for the Apache syntax to be correct you don't want to output a
comment on the same line as a statement. Comments in Apache need to be on
their own line.




Re: A multi line pattern match question

2016-07-14 Thread Omega -1911
On Thu, Jul 14, 2016 at 1:24 PM, Darryl Philip Baker <
darryl.ba...@northwestern.edu> wrote:

> On Thu, Jul 14, 2016 at 10:50 AM, Darryl Philip Baker <
> darryl.ba...@northwestern.edu> wrote:
>
> While not truly a beginner it feels that way after not doing anything
> substantial in Perl in many years.
>
>
>
> I currently need a program to take Apache HTTPD configuration files in
> HTTPD 2.2 syntax used in current production and convert them to HTTPD 2.4
> syntax in future production. I will need to do this many times weekly until
> we cut over to the new systems. My first challenge is converting the
> permissions syntax:
>
> Order deny,allow
>
> Deny from all
>
> To
>
> Require all denied
>
>
>
> Why not go line by line? Not 100% certain on the Apache syntax, but in
> your while loop where you are processing line by line:
>
>
>
> next if /Order\s+deny,\s*allow/i;  # Skip it in the output
>
>
>
> if( /(\s*)Deny\s+from\s+all/i) {
>
>
>
> my $leading_whitespace = $1;  # Preserve whatever whitespace is in the
> file now, could be multiple tabs and or spaces
>
>
>
> print $leading_whitespace . "Require all denied";
>
>
>
> }
>
> Learning from that example I came up with:
>
> $prevline = $_; # Save current line for
> later if needed
>
> # Change:
>
> #   Order deny,all
>
> #   Deny from all
>
> # To:
>
> #   Require all denied
>
> # No matter what case the first letters are
>
> if ( /Order\s+Deny,\s*Allow/i ) {
>
> next;
>
> chomp $_;
>
> if ( /(\s)Deny\s+from\s+All/i) {
>
> $whitespace = $1;
>
> print $whitespace, "Require all denied \# New Syntax\n";
>
> next;
>
> chomp $_;
>
> } else {
>
> print $prevline, " \# Old Syntax\n";
>
> }
>
> }
>
> It is not doing the expected. The “Order deny,allow” line is never output
> and where I want “Require all denied” the “Deny from all” is still being
> output.
>
>
>
> Darryl Baker
>
> PMOET -DAPS
>
> X76674
>
>
>

Hello,
I ran into a similar situation about 6 months ago and needed to change text
that spread multiple lines. Below is similar to what I used:

$_ =~ s/Order deny,allow.*?Deny from all/Require all denied/ims; #not the
best method but worked for me ##timtowtdi


RE: A multi line pattern match question

2016-07-14 Thread Darryl Philip Baker
On Thu, Jul 14, 2016 at 10:50 AM, Darryl Philip Baker 
 wrote:
While not truly a beginner it feels that way after not doing anything 
substantial in Perl in many years.

I currently need a program to take Apache HTTPD configuration files in HTTPD 
2.2 syntax used in current production and convert them to HTTPD 2.4 syntax in 
future production. I will need to do this many times weekly until we cut over 
to the new systems. My first challenge is converting the permissions syntax:
Order deny,allow
Deny from all
To
Require all denied

Why not go line by line? Not 100% certain on the Apache syntax, but in your 
while loop where you are processing line by line:

next if /Order\s+deny,\s*allow/i;  # Skip it in the output

if( /(\s*)Deny\s+from\s+all/i) {

my $leading_whitespace = $1;  # Preserve whatever whitespace is in the file 
now, could be multiple tabs and or spaces

print $leading_whitespace . "Require all denied";

}
Learning from that example I came up with:
$prevline = $_; # Save current line for later 
if needed
# Change:
#   Order deny,all
#   Deny from all
# To:
#   Require all denied
# No matter what case the first letters are
if ( /Order\s+Deny,\s*Allow/i ) {
next;
chomp $_;
if ( /(\s)Deny\s+from\s+All/i) {
$whitespace = $1;
print $whitespace, "Require all denied \# New Syntax\n";
next;
chomp $_;
} else {
print $prevline, " \# Old Syntax\n";
}
}
It is not doing the expected. The “Order deny,allow” line is never output and 
where I want “Require all denied” the “Deny from all” is still being output.

Darryl Baker
PMOET -DAPS
X76674



Re: A multi line pattern match question

2016-07-14 Thread Rob McAninch
On Thu, Jul 14, 2016 at 10:50 AM, Darryl Philip Baker <
darryl.ba...@northwestern.edu> wrote:

> While not truly a beginner it feels that way after not doing anything
> substantial in Perl in many years.
>
> I currently need a program to take Apache HTTPD configuration files in
> HTTPD 2.2 syntax used in current production and convert them to HTTPD 2.4
> syntax in future production. I will need to do this many times weekly until
> we cut over to the new systems. My first challenge is converting the
> permissions syntax:
> Order deny,allow
> Deny from all
> To
> Require all denied
>


Why not go line by line? Not 100% certain on the Apache syntax, but in your
while loop where you are processing line by line:

next if /Order\s+deny,\s*allow/i;  # Skip it in the output

if( /(\s*)Deny\s+from\s+all/i) {

my $leading_whitespace = $1;  # Preserve whatever whitespace is in the
file now, could be multiple tabs and or spaces

print $leading_whitespace . "Require all denied";

}


A multi line pattern match question

2016-07-14 Thread Darryl Philip Baker
While not truly a beginner it feels that way after not doing anything 
substantial in Perl in many years. 

I currently need a program to take Apache HTTPD configuration files in HTTPD 
2.2 syntax used in current production and convert them to HTTPD 2.4 syntax in 
future production. I will need to do this many times weekly until we cut over 
to the new systems. My first challenge is converting the permissions syntax:
Order deny,allow
Deny from all
To
Require all denied
And similar transformations. I was able to make this modification if I set $/ = 
undef and look at the file as a whole. My problem is I really want to process 
the file line by line to remove several  ...  blocks 
which may have other conditional code blocks contained within them. I have 
considered using two separate scripts and a two pass solution but there is a 
part of me which would rather have a single script do it all in one pass.

My current attempt, after several tries, is:
 if ( m/{.*}[Oo]rder deny,allow(.*)\n(.*)[Dd]eny from all(.*)/) {
print "\tRequire all denied\n";
next;
}
While not causing syntax errors it is not doing what I want either. I am 
probably using the 'm/' incorrectly and need your help.

Darryl Baker

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




Re: A multi line pattern match question

2016-07-14 Thread Andrew Solomon
I'm guessing the problem is the newline in the regex. If you want it to
match across multiple lines, I think the /ms modifiers should do the trick.

   if ( m/{.*}[Oo]rder deny,allow(.*)\n(.*)[Dd]eny from all(.*)/ms) {

NOTE: I haven't tried this myself!:)

failing that,

$ perldoc perlre

may be of help.


On Thu, Jul 14, 2016 at 3:50 PM, Darryl Philip Baker <
darryl.ba...@northwestern.edu> wrote:

> While not truly a beginner it feels that way after not doing anything
> substantial in Perl in many years.
>
> I currently need a program to take Apache HTTPD configuration files in
> HTTPD 2.2 syntax used in current production and convert them to HTTPD 2.4
> syntax in future production. I will need to do this many times weekly until
> we cut over to the new systems. My first challenge is converting the
> permissions syntax:
> Order deny,allow
> Deny from all
> To
> Require all denied
> And similar transformations. I was able to make this modification if I set
> $/ = undef and look at the file as a whole. My problem is I really want to
> process the file line by line to remove several  ...
>  blocks which may have other conditional code blocks contained
> within them. I have considered using two separate scripts and a two pass
> solution but there is a part of me which would rather have a single script
> do it all in one pass.
>
> My current attempt, after several tries, is:
>  if ( m/{.*}[Oo]rder deny,allow(.*)\n(.*)[Dd]eny from all(.*)/) {
> print "\tRequire all denied\n";
> next;
> }
> While not causing syntax errors it is not doing what I want either. I am
> probably using the 'm/' incorrectly and need your help.
>
> Darryl Baker
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 
Andrew Solomon

Mentor@Geekuni http://geekuni.com/
http://www.linkedin.com/in/asolomon


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

2016-05-13 Thread Walker, Michael E
Thank you for letting me know.

-Original Message-
From: Shawn H Corey [mailto:shawnhco...@gmail.com] 
Sent: Friday, May 13, 2016 10:01 AM
To: beginners@perl.org
Subject: Re: Start a New Thread for a New Question (WAS: This is one of the 
things ...)

On Fri, 13 May 2016 13:20:15 +
"Walker, Michael E"  wrote:

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

Hi Mike,

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


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

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





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




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

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

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

Hi Mike,

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


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

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




Re: regex capture question

2015-06-18 Thread Shlomi Fish
Hi Tiago,

Please reply to list if it's a mailing list post - http://shlom.in/reply .

On Thu, 18 Jun 2015 10:20:57 -0300
Tiago Hori  wrote:

> Folks,
> 
> I have the following regex: $_ =~ /(Crosses)(.*)(misses=)(\d+)/s
> 
> It does what I need to do in terms of matching, but I also want to use the
> capture parenthesis. The data comes from tab-limited files and I use $4 to
> grab the last digits of the match, however it is also matching the trailing
> tab. I solved it by stripping of the tabs from the line, but I can figure
> out why (\d+) is also matching the tab!
> 

That sounds strange and perl should not do that. Can you post a self-contained
and reproducing example that exhibits this behaviour? Sometimes reducing your
code to the bare reproducing minimum helps in finding where the problem is. I
could also use some information about your system (OS, distribution, perl,
versions , CPU architecture, etc.)

Regards,

Shlomi Fish

> T.
> 



-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/ways_to_do_it.html

Chuck Norris can construct any logical expression using only AND gates.
— http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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




Re: regex capture question

2015-06-18 Thread Илья Рассадин
Hi, Tiago!

I can't reproduce such behaviour

use Modern::Perl '2014';
my $string = 'Crosses   misses=50   ';
my (@matches) = ($string =~ /(Crosses)(.*)(misses=)(\d+)/s);

use Data::Dumper;
print Dumper \@matches;

result:
$VAR1 = [
  'Crosses',
  ' ',
  'misses=',
  '50'
];

As you see, no tabs in $matches[3];

Please, publish string that you try to parse with this regexp.


чт, 18 июня 2015 г. в 16:24, Tiago Hori :

> Folks,
>
> I have the following regex: $_ =~ /(Crosses)(.*)(misses=)(\d+)/s
>
> It does what I need to do in terms of matching, but I also want to use the
> capture parenthesis. The data comes from tab-limited files and I use $4 to
> grab the last digits of the match, however it is also matching the trailing
> tab. I solved it by stripping of the tabs from the line, but I can figure
> out why (\d+) is also matching the tab!
>
> T.
>
> --
> "Education is not to be used to promote obscurantism." - Theodonius
> Dobzhansky.
>
> "Gracias a la vida que me ha dado tanto
> Me ha dado el sonido y el abecedario
> Con él, las palabras que pienso y declaro
> Madre, amigo, hermano
> Y luz alumbrando la ruta del alma del que estoy amando
>
> Gracias a la vida que me ha dado tanto
> Me ha dado la marcha de mis pies cansados
> Con ellos anduve ciudades y charcos
> Playas y desiertos, montañas y llanos
> Y la casa tuya, tu calle y tu patio"
>
> Violeta Parra - Gracias a la Vida
>
> Tiago S. F. Hori. PhD.
> Ocean Science Center-Memorial University of Newfoundland
>


regex capture question

2015-06-18 Thread Tiago Hori
Folks,

I have the following regex: $_ =~ /(Crosses)(.*)(misses=)(\d+)/s

It does what I need to do in terms of matching, but I also want to use the
capture parenthesis. The data comes from tab-limited files and I use $4 to
grab the last digits of the match, however it is also matching the trailing
tab. I solved it by stripping of the tabs from the line, but I can figure
out why (\d+) is also matching the tab!

T.

-- 
"Education is not to be used to promote obscurantism." - Theodonius
Dobzhansky.

"Gracias a la vida que me ha dado tanto
Me ha dado el sonido y el abecedario
Con él, las palabras que pienso y declaro
Madre, amigo, hermano
Y luz alumbrando la ruta del alma del que estoy amando

Gracias a la vida que me ha dado tanto
Me ha dado la marcha de mis pies cansados
Con ellos anduve ciudades y charcos
Playas y desiertos, montañas y llanos
Y la casa tuya, tu calle y tu patio"

Violeta Parra - Gracias a la Vida

Tiago S. F. Hori. PhD.
Ocean Science Center-Memorial University of Newfoundland


Re: Perl array question

2015-05-06 Thread Marius Gavrilescu
anirban.adhik...@gmail.com (Anirban Adhikary) writes:

> Hi List
> I have the following array ---
> ('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8');
> There are two part for each element separated by a dash.
> first one known as earfcn and second one is pcid .
> The requirement is  For the same “earfcn”, concatenate the “pcid” values
> using "&" separator between values.
> so the output will be like this
> EARFCN=1900,PCID=0&1&2&4;
> EARFCN=1902,PCID=5&6&7&8;

Use a hash from earfcn to an array of pcids.

#!/usr/bin/perl
use v5.14;
use warnings;

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

my %hash;

for (@arr) {
	my ($earfcn, $pcid) = split /-/;
	next unless $pcid; # Skip the NULLs
	$hash{$earfcn} //= [];
	push @{$hash{$earfcn}}, $pcid;
}

for my $earfcn (keys %hash) {
	say "EARFCN=$earfcn,PCID=", join '&', @{$hash{$earfcn}};
}
-- 
Marius Gavrilescu


signature.asc
Description: PGP signature


Fwd: Fw: Perl array question

2015-05-06 Thread Shlomi Fish
-- Forwarded message --
From: Shlomi Fish 
Date: Wed, May 6, 2015 at 11:31 AM
Subject: Fw: Perl array question
To: shlo...@gmail.com




Begin forwarded message:

Date: Wed, 6 May 2015 11:04:30 +0300
From: Shlomi Fish 
To: beginners 
Subject: Re: Perl array question


Hi Anirban,

please reply to all recipients.

On Wed, 6 May 2015 12:49:53 +0530
Anirban Adhikary  wrote:

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

Use a hash of arrays/etc:

< CODE >
#!/usr/bin/perl

use strict;
use warnings;

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

my %earfcns;

foreach my $item (@arr)
{
if ($item ne 'NULL')
{
if (my ($ear, $pcid) = $item =~ /\A([0-9]+)-([0-9]+)\z/)
{
push @{ $earfcns{$ear} } , $pcid;
}
else
{
die "Invalid item <<$item>>!";
}
}
}

foreach my $ear (sort { $a <=> $b } keys(%earfcns))
{
print "EARFCN=$ear,PCID="
. join("&", sort { $a <=> $b } @{$earfcns{$ear}})
. ";\n"
;
}

< END CODE >

For more information, see:

* http://perl-begin.org/topics/hashes/

* http://perl-begin.org/topics/references/

(*NOTE*: perl-begin.org is a site that I happen to maintain).

Regards,

Shlomi Fish

> Best Regards
> Anirban.



--
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/bits/facts/Summer-Glau/

The prefix “God Said” has the extraordinary logical property of converting
any
statement that follows it into a true one.

Please reply to list if it's a mailing list post - http://shlom.in/reply .


--
-
Shlomi Fish   http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

NASA Uses COBOL.
— http://is.gd/ClKAz5

Please reply to list if it's a mailing list post - http://shlom.in/reply .



-- 
--
Shlomi Fish http://www.shlomifish.org/

Chuck Norris helps the gods that help themselves.

Please reply to list if it's a mailing list post - http://shlom.in/reply .


Re: Perl array question

2015-05-06 Thread Shawn H Corey
On Wed, 6 May 2015 12:49:53 +0530
Anirban Adhikary  wrote:

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

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

#!/usr/bin/env perl

use strict;
use warnings;

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

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

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


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

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




Re: Perl array question

2015-05-06 Thread Vincent Lequertier
Thank you for the review, I'm learning and didn't know about this way of 
using hashes :-)


---
Vincent Lequertier
s...@riseup.net

Le 2015-05-06 11:09, Shlomi Fish a écrit :

Hi Vincent,

On Wed, 06 May 2015 10:07:41 +0200
Vincent Lequertier  wrote:


It's a bit ugly, but here is one way to do it :



Your code encourages many bad practices. Some notes are:


#!/usr/bin/perl


no "use strict;"/"use warnings;":

http://perl-begin.org/tutorials/bad-elements/#no-strict-and-warnings


my @array = ('1900-0', '1900-1', 'NULL', 'NULL', '1900-2', '1900-4',
'1902-5', '1902-6', '1902-7', '1902-8');
my $num1900 = 'EARFCN=1900, PCID=';
my $num1902 = 'EARFCN=1902, PCID=';


That's varvarname:

http://perl-begin.org/tutorials/bad-elements/#varvarname


for (@array) {


Iterating using "$_":

http://perl-begin.org/tutorials/bad-elements/#overuse_dollar_underscore


 # print $_ . "\n";
 $num1900 .= (split '-', $_)[1] . '&'
 if $_ =~ /1900/;
 $num1902 .= (split '-', $_)[1] . '&'
 if $_ =~ /1902/;


Duplicate code and you really should use a datastructure and less error 
prone

parsing.


}
$num1900 =~ s/\&$/;/;
$num1902 =~ s/\&$/;/;


"&" has no special meaning in regexes , so there is no reason to 
backslash it

(it doesn't hurt though).


print $num1900 . "\n";
print $num1902;


There should be a newline here too for good measure.

Regards,

Shlomi Fish


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




Re: Perl array question

2015-05-06 Thread Shlomi Fish
Hi Vincent,

On Wed, 06 May 2015 10:07:41 +0200
Vincent Lequertier  wrote:

> It's a bit ugly, but here is one way to do it :
> 

Your code encourages many bad practices. Some notes are:

> #!/usr/bin/perl

no "use strict;"/"use warnings;":

http://perl-begin.org/tutorials/bad-elements/#no-strict-and-warnings

> my @array = ('1900-0', '1900-1', 'NULL', 'NULL', '1900-2', '1900-4', 
> '1902-5', '1902-6', '1902-7', '1902-8');
> my $num1900 = 'EARFCN=1900, PCID=';
> my $num1902 = 'EARFCN=1902, PCID=';

That's varvarname:

http://perl-begin.org/tutorials/bad-elements/#varvarname

> for (@array) {

Iterating using "$_":

http://perl-begin.org/tutorials/bad-elements/#overuse_dollar_underscore

>  # print $_ . "\n";
>  $num1900 .= (split '-', $_)[1] . '&'
>  if $_ =~ /1900/;
>  $num1902 .= (split '-', $_)[1] . '&'
>  if $_ =~ /1902/;

Duplicate code and you really should use a datastructure and less error prone
parsing.

> }
> $num1900 =~ s/\&$/;/;
> $num1902 =~ s/\&$/;/;

"&" has no special meaning in regexes , so there is no reason to backslash it
(it doesn't hurt though).

> print $num1900 . "\n";
> print $num1902;

There should be a newline here too for good measure.

Regards,

Shlomi Fish


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




Fwd: Fw: Perl array question

2015-05-06 Thread Shlomi Fish
-- Forwarded message --
From: Shlomi Fish 
Date: Wed, May 6, 2015 at 11:31 AM
Subject: Fw: Perl array question
To: shlo...@gmail.com




Begin forwarded message:

Date: Wed, 6 May 2015 11:04:30 +0300
From: Shlomi Fish 
To: beginners 
Subject: Re: Perl array question


Hi Anirban,

please reply to all recipients.

On Wed, 6 May 2015 12:49:53 +0530
Anirban Adhikary  wrote:

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

Use a hash of arrays/etc:

< CODE >
#!/usr/bin/perl

use strict;
use warnings;

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

my %earfcns;

foreach my $item (@arr)
{
if ($item ne 'NULL')
{
if (my ($ear, $pcid) = $item =~ /\A([0-9]+)-([0-9]+)\z/)
{
push @{ $earfcns{$ear} } , $pcid;
}
else
{
die "Invalid item <<$item>>!";
}
}
}

foreach my $ear (sort { $a <=> $b } keys(%earfcns))
{
print "EARFCN=$ear,PCID="
. join("&", sort { $a <=> $b } @{$earfcns{$ear}})
. ";\n"
;
}

< END CODE >

For more information, see:

* http://perl-begin.org/topics/hashes/

* http://perl-begin.org/topics/references/

(*NOTE*: perl-begin.org is a site that I happen to maintain).

Regards,

Shlomi Fish

> Best Regards
> Anirban.



--
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/bits/facts/Summer-Glau/

The prefix “God Said” has the extraordinary logical property of converting
any
statement that follows it into a true one.

Please reply to list if it's a mailing list post - http://shlom.in/reply .


--
-
Shlomi Fish   http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

NASA Uses COBOL.
— http://is.gd/ClKAz5

Please reply to list if it's a mailing list post - http://shlom.in/reply .



-- 
--
Shlomi Fish http://www.shlomifish.org/

Chuck Norris helps the gods that help themselves.

Please reply to list if it's a mailing list post - http://shlom.in/reply .


Re: Perl array question

2015-05-06 Thread Vincent Lequertier

It's a bit ugly, but here is one way to do it :

#!/usr/bin/perl
my @array = ('1900-0', '1900-1', 'NULL', 'NULL', '1900-2', '1900-4', 
'1902-5', '1902-6', '1902-7', '1902-8');

my $num1900 = 'EARFCN=1900, PCID=';
my $num1902 = 'EARFCN=1902, PCID=';
for (@array) {
# print $_ . "\n";
$num1900 .= (split '-', $_)[1] . '&'
if $_ =~ /1900/;
$num1902 .= (split '-', $_)[1] . '&'
if $_ =~ /1902/;
}
$num1900 =~ s/\&$/;/;
$num1902 =~ s/\&$/;/;
print $num1900 . "\n";
print $num1902;

Cheers !
---
Vincent Lequertier
s...@riseup.net

Le 2015-05-06 09:19, Anirban Adhikary a écrit :

Hi List
I have the following array ---
('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8');
There are two part for each element separated by a dash.
first one known as earfcn and second one is pcid .
The requirement is  For the same “earfcn”, concatenate the “pcid” 
values

using "&" separator between values.
so the output will be like this
EARFCN=1900,PCID=0&1&2&4;
EARFCN=1902,PCID=5&6&7&8;

I am not able to generate any idea how to adress this isuue. Please 
give me

some starting point.

Best Regards
Anirban.


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




Perl array question

2015-05-06 Thread Anirban Adhikary
Hi List
I have the following array ---
('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8');
There are two part for each element separated by a dash.
first one known as earfcn and second one is pcid .
The requirement is  For the same “earfcn”, concatenate the “pcid” values
using "&" separator between values.
so the output will be like this
EARFCN=1900,PCID=0&1&2&4;
EARFCN=1902,PCID=5&6&7&8;

I am not able to generate any idea how to adress this isuue. Please give me
some starting point.

Best Regards
Anirban.


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

2015-01-28 Thread Harry Putnam
Brandon McCaig  writes:

[...] snipped excellent extrapolation

> I hope that helps.

Well, I could not have asked for a fuller answer... thanks.


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




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

2015-01-28 Thread Harry Putnam
Shawn H Corey  writes:

> On Tue, 27 Jan 2015 09:37:15 -0500
> Harry Putnam  wrote:
>
>> #!/usr/local/src/test/bin/perl
>> 
>> use strict;
>> use warnings;
>> use Cwd 'abs_path';
>> 
>> my $tdir = shift;
>> 
>
> You can use `-e` to determine if the path exists and `-d` to determine
> if it's a directory. See `perldoc -f -X` and search for /-e/ and /-d/,
> http://perldoc.perl.org/functions/-X.html

Thanks, yes.. I knew about -d but was looking to get there in one
move

>From OP:
"In the following code I hoped to use `use Cwd abs_path;' to not
only produce the absolute path for a  named directory but to die if it
could not... thereby getting around having to test the named dir with
-d ... to make sure it was really a directory in the fs."

Note the comment after `not...'

So, just thought, why not skip a step.

But I see the sense in the discussion brought by Brandon M. 


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




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

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

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

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


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


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

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




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

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

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

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


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

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




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

2015-01-27 Thread Brandon McCaig
Harry:

On Tue, Jan 27, 2015 at 9:37 AM, Harry Putnam  wrote:
> In the following code I hoped to use `use Cwd abs_path;' to not
> only produce the absolute path for a  named directory but to die if it
> could not... thereby getting around having to test the named dir with
> -d ... to make sure it was really a directory in the fs.
>
> It does not have that effect when a bogus directory is passed in, and,
> in fact, goes on to the chdir to find out its bogus.
>
> Why is that?
>
> --- 8< snip -- 8< snip -- 8
> #!/usr/local/src/test/bin/perl
>
> use strict;
> use warnings;
> use Cwd 'abs_path';
>
> my $tdir = shift;
>
> $tdir = abs_path($tdir)  or die "Can't find  <$tdir>: $!";
>
> chdir $tdir or die "Can't chdir <$tdir>: $!";
>
> print "Hello from $tdir\n";

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

In general the documentation for a function or module should be
consulted to learn of how it handles errors. Most often die() implies
that something in the program state is invalid and the program cannot
continue. This typically implies an "impossible" or "exceptional"
situation. When the simple fact that an operation failed is sufficient
it is often good enough to return an error code (e.g., undef or an
empty list, or perhaps a two-item list with an error as the second
item) and let the caller decide if this is a serious error or not.
Often the $! variable is set to an appropriate error code that is more
descriptive of the error. That works well for many errors.

Often die() is called directly by you. When die() is called (and its
string doesn't end in a newline) it reports the line where it was
called as the source of the error. There is a module, Carp, that is
often used to die() from within modules by pointing at your invocation
of the module (e.g., where you called the module) as the source of the
error instead of the module itself being wrong. Modules will generally
tell you if they die() or use Carp, and often that behavior can be
toggled on or off with flags. There is also an 'autodie' pragma that
allows many system functions to die() automatically. chdir() is
supported by it if you're interested in that.

I do not believe that the intent of abs_path() is to tell you whether
that path exists. It is merely there to resolve a relative path into
an absolute path. You might do so in order to create a new file with
that path, and then tell the user what that full path is so there is
no ambiguity. If it were to die() when that path didn't exist it would
be impossible to resolve non-existent paths, which would limit the
function's usefulness.

I hope that helps.

Regards,


-- 
Brandon McCaig  
Castopulence Software 
Blog 
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'

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




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

2015-01-27 Thread Harry Putnam
In the following code I hoped to use `use Cwd abs_path;' to not
only produce the absolute path for a  named directory but to die if it
could not... thereby getting around having to test the named dir with
-d ... to make sure it was really a directory in the fs.

It does not have that effect when a bogus directory is passed in, and,
in fact, goes on to the chdir to find out its bogus.

Why is that?

--- 8< snip -- 8< snip -- 8: $!";

chdir $tdir or die "Can't chdir <$tdir>: $!";

print "Hello from $tdir\n";


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




Re: Philosophical Question About Group

2014-08-02 Thread ESChamp
Thanks, Shawn. Responses are inline, below.

Shawn H Corey wrote on 8/2/2014 3:49 PM:
> On Sat, 02 Aug 2014 15:01:50 -0400
> ESChamp  wrote:
> 
>> So what I'm asking is, how does a person like me ask questions here
>> that are likely to produce what I need?
> 
> 1. Post the code of what you have tried. It's hard to give useful advice
> without specifics.

Recently, I asked about a program i had been using successfully for a
long time, that had suddenly failed in one section. I posted the
fragment of code that provoked the error message (it was looking for a
line in the data file that was only ) and the section of the data
file above and below 


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




Re: Philosophical Question About Group

2014-08-02 Thread Shawn H Corey
On Sat, 02 Aug 2014 15:01:50 -0400
ESChamp  wrote:

> So what I'm asking is, how does a person like me ask questions here
> that are likely to produce what I need?

1. Post the code of what you have tried. It's hard to give useful advice
without specifics.

2. Ask about one problem per thread. If you post more than one, only
one of them may be covered extensively and the rest may receive little
or no attention.

3. Do not attach a new problem to an existing thread. Only those who
are following the thread will read it and that will reduce the possible
answers.

4. Have patience. Everyone here is a volunteer and may not get back to
you in quite a while. Allow 24 hours to past before you think the
thread is dead.


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

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




Philosophical Question About Group

2014-08-02 Thread ESChamp
When I think of the word "beginners", I think of people starting out to
learn perl and looking for advice.

I'm actually not a beginner but a sort of "returner". Almost 80 years
old, I use an occasional perl script to do a job that has to be repeated
a couple of times a week, or one that is used once or twice for
something that is too tedious to be done by hand.

I used "A Little Book on Perl" (199) as my guide, because it is simple
and uses the constructs that are easily understandable when/if I ever
look at the script again. I was never a real perl programmer but knew
enough to get by. Did I mention that this was 20 or more years ago?

People have been very helpful to me here, but unfortunately, because I'm
not looking to learn perl, much of their advice goes unheeded despite
its value to a beginner.

So what I'm asking is, how does a person like me ask questions here that
are likely to produce what I need?

Thanks.

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




Critique of simple spell check interview question

2014-07-19 Thread Kartik Thakore
Hi Perl!

I recently was applying for jobs and did the following implementation for
the problem below:

https://github.com/kthakore/InterviewProblems

I was wondering if I could get some critique of my code as I haven't been
writing "readable" code for others to read in quite a while.

Also is there a better way to do:

https://github.com/kthakore/InterviewProblems/blob/master/lib/Correct/Duplicate.pm#L5

Regards,
Karitk


Re: question on escaping shell command

2014-05-16 Thread Chris Knipe
Thanks for all the suggestions and replies guys.

After further investigation, it seems the bug is rather in the shell
program itself.  Even if reading the values from a text file instead
of STDIN, it still refuses to parse anything beyond a # character.

I've altered my code to use Authen::Radius instead, and it seems to be
working better.

--
Chris.


On Fri, May 16, 2014 at 10:54 AM, Simon Foutaiz  wrote:
> You can take a look at the IPC::Cmd module that should remove some pain when
> dealing with system commands through Perl.
>
>  https://metacpan.org/pod/IPC::Cmd
>
>
> On Thu, May 15, 2014 at 3:10 PM, Chris Knipe  wrote:
>>
>> Hi All,
>>
>> I'm having a bit of a strange issue executing a system command through
>> perl.
>> The system command reads a bunch of parameters through STDIN, and responds
>> via STDOUT.  The problem is that special commands (notably the "#" and "!"
>> character.  Perl itself, escapes the characters correctly (as indicated
>> through the print $RADCommand code), but the command once executed through
>> the shell, but from there it goes pear shaped once the system executes the
>> command..
>>
>> A quick example:
>> use Data::Dumper;
>> use strict;
>> use warnings;
>> my $AuthName = "user\@domain.com";
>> my $AuthPass = "!\@#bsay0nd";
>> my $ClientIP = "10.0.0.3";
>> my $RADCommand = "/bin/echo -e ";
>> $RADCommand .= "Called-Station-Id = x.x.x.42, ";
>> $RADCommand .= "Calling-Station-Id = " . $ClientIP . ", ";
>> $RADCommand .= "Login-Service = Telnet, ";
>> $RADCommand .= "Login-TCP-Port = 119, ";
>> $RADCommand .= "NAS-IP-Address = 10.255.255.245, ";
>> $RADCommand .= "NAS-Port-Type = Virtual, ";
>> $RADCommand .= "Service-Type = Authenticate-Only, ";
>> $RADCommand .= "User-Name = " . $AuthName . ", ";
>> $RADCommand .= "User-Password = " . $AuthPass . " ";
>> $RADCommand .= "| /usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
>> quaap5hooZae4ahNguehusieg0Oiph1u";
>> my @RADResult = qx($RADCommand);
>> print $RADCommand . "\n";
>> print Dumper(@RADResult);
>>
>> The output of the above code is correct:
>> /bin/echo -e Called-Station-Id = 85.12.8.42, Calling-Station-Id =
>> 198.19.255.3, Login-Service = Telnet, Login-TCP-Port = 119, NAS-IP-Address
>> =
>> 10.255.255.245, NAS-Port-Type = Virtual, Service-Type = Authenticate-Only,
>> User-Name = gar...@beyondonline.co.za, User-Password = !@#Bey0nd |
>> /usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
>> quaap5hooZae4ahNguehusieg0Oiph1u
>> $VAR1 = 'Received response ID 198, code 3, length = 55
>> ';
>> $VAR2 = '   Reply-Message = "NOK:Authentication failed"
>> ';
>>
>> However, once executing the command, the RADIUS server receives the
>> incorrect string for the password:
>> Thu May 15 09:57:46 2014
>> Packet-Type = Access-Request
>> Called-Station-Id = "x.x.x.42"
>> Calling-Station-Id = "10.0.0.3"
>> Login-Service = Telnet
>> Login-TCP-Port = 119
>> NAS-IP-Address = 10.255.255.245
>> NAS-Port-Type = Virtual
>> Service-Type = Authenticate-Only
>> User-Name = " u...@domain.com"
>> User-Password = "!@"
>> Realm = "DEFAULT"
>>
>> The problem is a shell problem rather than a perl problem, I do know that
>> much.  Nevermind what I do or where I put quotes / escape strings, I
>> cannot
>> get bash to execute the echo statement.
>>
>> Can anyone shed some light on this subject perhaps?  I know it's more than
>> likely a little bit off topic, but I would appreciate the assistance.
>>
>> --
>> Chris.
>>
>>
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>



-- 

Regards,
Chris Knipe

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




Re: question on escaping shell command

2014-05-16 Thread Simon Foutaiz
You can take a look at the IPC::Cmd module that should remove some pain
when dealing with system commands through Perl.

 https://metacpan.org/pod/IPC::Cmd


On Thu, May 15, 2014 at 3:10 PM, Chris Knipe  wrote:

> Hi All,
>
> I'm having a bit of a strange issue executing a system command through
> perl.
> The system command reads a bunch of parameters through STDIN, and responds
> via STDOUT.  The problem is that special commands (notably the "#" and "!"
> character.  Perl itself, escapes the characters correctly (as indicated
> through the print $RADCommand code), but the command once executed through
> the shell, but from there it goes pear shaped once the system executes the
> command..
>
> A quick example:
> use Data::Dumper;
> use strict;
> use warnings;
> my $AuthName = "user\@domain.com";
> my $AuthPass = "!\@#bsay0nd";
> my $ClientIP = "10.0.0.3";
> my $RADCommand = "/bin/echo -e ";
> $RADCommand .= "Called-Station-Id = x.x.x.42, ";
> $RADCommand .= "Calling-Station-Id = " . $ClientIP . ", ";
> $RADCommand .= "Login-Service = Telnet, ";
> $RADCommand .= "Login-TCP-Port = 119, ";
> $RADCommand .= "NAS-IP-Address = 10.255.255.245, ";
> $RADCommand .= "NAS-Port-Type = Virtual, ";
> $RADCommand .= "Service-Type = Authenticate-Only, ";
> $RADCommand .= "User-Name = " . $AuthName . ", ";
> $RADCommand .= "User-Password = " . $AuthPass . " ";
> $RADCommand .= "| /usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
> quaap5hooZae4ahNguehusieg0Oiph1u";
> my @RADResult = qx($RADCommand);
> print $RADCommand . "\n";
> print Dumper(@RADResult);
>
> The output of the above code is correct:
> /bin/echo -e Called-Station-Id = 85.12.8.42, Calling-Station-Id =
> 198.19.255.3, Login-Service = Telnet, Login-TCP-Port = 119, NAS-IP-Address
> =
> 10.255.255.245, NAS-Port-Type = Virtual, Service-Type = Authenticate-Only,
> User-Name = gar...@beyondonline.co.za, User-Password = !@#Bey0nd |
> /usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
> quaap5hooZae4ahNguehusieg0Oiph1u
> $VAR1 = 'Received response ID 198, code 3, length = 55
> ';
> $VAR2 = '   Reply-Message = "NOK:Authentication failed"
> ';
>
> However, once executing the command, the RADIUS server receives the
> incorrect string for the password:
> Thu May 15 09:57:46 2014
> Packet-Type = Access-Request
> Called-Station-Id = "x.x.x.42"
> Calling-Station-Id = "10.0.0.3"
> Login-Service = Telnet
> Login-TCP-Port = 119
> NAS-IP-Address = 10.255.255.245
> NAS-Port-Type = Virtual
> Service-Type = Authenticate-Only
> User-Name = " u...@domain.com"
> User-Password = "!@"
> Realm = "DEFAULT"
>
> The problem is a shell problem rather than a perl problem, I do know that
> much.  Nevermind what I do or where I put quotes / escape strings, I cannot
> get bash to execute the echo statement.
>
> Can anyone shed some light on this subject perhaps?  I know it's more than
> likely a little bit off topic, but I would appreciate the assistance.
>
> --
> Chris.
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: question on escaping shell command

2014-05-15 Thread Robert Wohlfarth
On Thu, May 15, 2014 at 3:10 AM, Chris Knipe  wrote:

> I'm having a bit of a strange issue executing a system command through
> perl.
> The system command reads a bunch of parameters through STDIN, and responds
> via STDOUT.  The problem is that special commands (notably the "#" and "!"
> character.  Perl itself, escapes the characters correctly (as indicated
> through the print $RADCommand code), but the command once executed through
> the shell, but from there it goes pear shaped once the system executes the
> command..
>
> A quick example:
> use Data::Dumper;
> use strict;
> use warnings;
> my $AuthName = "user\@domain.com";
> my $AuthPass = "!\@#bsay0nd";
>

Try escaping the "#" for the shell, like this: my $AuthPass =
"!\@\\#bsay0nd"; The shell sees the "#" and treats the rest of the line
like a comment. When passing "!@\#bsay0nd" to the shell, it interprets "#"
as a literal character instead.

-- 
Robert Wohlfarth


question on escaping shell command

2014-05-15 Thread Chris Knipe
Hi All,

I'm having a bit of a strange issue executing a system command through perl.
The system command reads a bunch of parameters through STDIN, and responds
via STDOUT.  The problem is that special commands (notably the "#" and "!"
character.  Perl itself, escapes the characters correctly (as indicated
through the print $RADCommand code), but the command once executed through
the shell, but from there it goes pear shaped once the system executes the
command.. 

A quick example:
use Data::Dumper;
use strict;
use warnings;
my $AuthName = "user\@domain.com";
my $AuthPass = "!\@#bsay0nd";
my $ClientIP = "10.0.0.3";
my $RADCommand = "/bin/echo -e ";
$RADCommand .= "Called-Station-Id = x.x.x.42, ";
$RADCommand .= "Calling-Station-Id = " . $ClientIP . ", ";
$RADCommand .= "Login-Service = Telnet, ";
$RADCommand .= "Login-TCP-Port = 119, ";
$RADCommand .= "NAS-IP-Address = 10.255.255.245, ";
$RADCommand .= "NAS-Port-Type = Virtual, ";
$RADCommand .= "Service-Type = Authenticate-Only, ";
$RADCommand .= "User-Name = " . $AuthName . ", ";
$RADCommand .= "User-Password = " . $AuthPass . " ";
$RADCommand .= "| /usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
quaap5hooZae4ahNguehusieg0Oiph1u";
my @RADResult = qx($RADCommand);
print $RADCommand . "\n";
print Dumper(@RADResult);

The output of the above code is correct:
/bin/echo -e Called-Station-Id = 85.12.8.42, Calling-Station-Id =
198.19.255.3, Login-Service = Telnet, Login-TCP-Port = 119, NAS-IP-Address =
10.255.255.245, NAS-Port-Type = Virtual, Service-Type = Authenticate-Only,
User-Name = gar...@beyondonline.co.za, User-Password = !@#Bey0nd |
/usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
quaap5hooZae4ahNguehusieg0Oiph1u
$VAR1 = 'Received response ID 198, code 3, length = 55
';
$VAR2 = '   Reply-Message = "NOK:Authentication failed"
';

However, once executing the command, the RADIUS server receives the
incorrect string for the password:
Thu May 15 09:57:46 2014
Packet-Type = Access-Request
Called-Station-Id = "x.x.x.42"
Calling-Station-Id = "10.0.0.3"
Login-Service = Telnet
Login-TCP-Port = 119
NAS-IP-Address = 10.255.255.245
NAS-Port-Type = Virtual
Service-Type = Authenticate-Only
User-Name = " u...@domain.com"
User-Password = "!@"
Realm = "DEFAULT"

The problem is a shell problem rather than a perl problem, I do know that
much.  Nevermind what I do or where I put quotes / escape strings, I cannot
get bash to execute the echo statement.

Can anyone shed some light on this subject perhaps?  I know it's more than
likely a little bit off topic, but I would appreciate the assistance.

--
Chris.



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




Mogilefs Question

2014-03-06 Thread Yonghua Peng
 Hello,

Since Mogilefs is written with Perl and I asked the question on the list of 
Mogilefs but didn't get an answer, so I reposted the question here.

What server is suggested for running the front server for mogilefs?
Currently we are running Nginx with mogilefs module which has been patched.
But sometime we found accessing to the storage via nginx is not robust (get a 
40x, 50x error etc).
After reloading nginx the issue gets fine.
So what's the alternative to nginx as a front server for mogilefs?

Thanks.


--
looking for cloud developers: 
http://www.nsbeta.info/jobs

Re: Regrex Question

2013-11-25 Thread shawn wilson
Take it out of the loop and add /s if it could span lines.

On Mon, Nov 25, 2013 at 2:44 PM, Mike Blezien  wrote:
> Thank you for your and the other list members suggestions, gives me a good
> place to start.
>
>
> Mike(mickalo)Blezien
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Thunder Rain Internet Publishing
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>
> - Original Message -
> From: Jim Gibson
> To: Perl List
> Sent: Monday, November 25, 2013 1:23 PM
> Subject: Re: Regrex Question
>
>
> On Nov 25, 2013, at 10:55 AM, Mike Blezien wrote:
>
>> Hello,
>>
>> Regular expression have never been my strong suite so hoping to get a
>> litte help with a line in file I need to extract a portion of it.
>>
>> The text I need to extract from this line is "November 21, 2013" from this
>> line in the file, just the date:
>>
>> Posted by mailto:someem...@email.com";>Some Name on November
>> 21, 2013 at 23:21:58:
>>
>> what would be the regrex to use to extract the date from the line ?
>
> The usual advice applies: don't use regular expressions to parse HTML.
> However, lots of people do it anyway, myself included. Your success at
> extracting usable data depends upon how rigid the format of the HTML is from
> page to page.
>
> In your case, if the date always follows a link ('') followed by 'on',
> and the date is always followed by 'at' and a time. you can use this:
>
>   if( $line =~ m{  \s+ on \s+ (\w+ \s \d{1,2} , \s \d{4}) \s at}x ) {
> print "The date is $1\n";
>   }else{
> print "No match\n";
>   }
>
> Note I am using the extended regular expression syntax with the x modifier.
>
>
> --
> 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: Regrex Question

2013-11-25 Thread Mike Blezien
Thank you for your and the other list members suggestions, gives me a good 
place to start.


Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  - Original Message - 
  From: Jim Gibson 
  To: Perl List 
  Sent: Monday, November 25, 2013 1:23 PM
  Subject: Re: Regrex Question



  On Nov 25, 2013, at 10:55 AM, Mike Blezien wrote:

  > Hello,
  >  
  > Regular expression have never been my strong suite so hoping to get a litte 
help with a line in file I need to extract a portion of it.
  >  
  > The text I need to extract from this line is "November 21, 2013" from this 
line in the file, just the date:
  >  
  > Posted by mailto:someem...@email.com";>Some Name on November 
21, 2013 at 23:21:58:
  >  
  > what would be the regrex to use to extract the date from the line ?

  The usual advice applies: don't use regular expressions to parse HTML. 
However, lots of people do it anyway, myself included. Your success at 
extracting usable data depends upon how rigid the format of the HTML is from 
page to page.

  In your case, if the date always follows a link ('') followed by 'on', 
and the date is always followed by 'at' and a time. you can use this:

if( $line =~ m{  \s+ on \s+ (\w+ \s \d{1,2} , \s \d{4}) \s at}x ) {
  print "The date is $1\n";
}else{
  print "No match\n";
}

  Note I am using the extended regular expression syntax with the x modifier.


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




Re: Regrex Question

2013-11-25 Thread Jim Gibson

On Nov 25, 2013, at 10:55 AM, Mike Blezien wrote:

> Hello,
>  
> Regular expression have never been my strong suite so hoping to get a litte 
> help with a line in file I need to extract a portion of it.
>  
> The text I need to extract from this line is "November 21, 2013" from this 
> line in the file, just the date:
>  
> Posted by mailto:someem...@email.com";>Some Name on November 21, 
> 2013 at 23:21:58:
>  
> what would be the regrex to use to extract the date from the line ?

The usual advice applies: don't use regular expressions to parse HTML. However, 
lots of people do it anyway, myself included. Your success at extracting usable 
data depends upon how rigid the format of the HTML is from page to page.

In your case, if the date always follows a link ('') followed by 'on', and 
the date is always followed by 'at' and a time. you can use this:

  if( $line =~ m{  \s+ on \s+ (\w+ \s \d{1,2} , \s \d{4}) \s at}x ) {
print "The date is $1\n";
  }else{
print "No match\n";
  }

Note I am using the extended regular expression syntax with the x modifier.


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




Re: Regrex Question

2013-11-25 Thread Peter Gordon
On Mon, 25 Nov 2013 12:55:35 -0600, Mike Blezien wrote:
>Hello,
>
>Regular expression have never been my strong suite so hoping to get
>a litte help with a line in file I need to extract a portion of it.
>
>The text I need to extract from this line is "November 21, 2013"
>from this line in the file, just the date:
>
>Posted by mailto:someem...@email.com";>Some Name on
>November 21, 2013 at 23:21:58:
>
>what would be the regrex to use to extract the date from the line ?
>
>Thanks,
>
>Mike(mickalo)Blezien
>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>Thunder Rain Internet Publishing
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

My attempt:

#! /usr/bin/perl -w
use 5.14.0;
use strict;
while( <> ) {
if ( /(?:.*?)(\w+ \d+, \d+) at .*$/ ) {
print "$1\n";
}
}
--
Peter Gordon, pete...@netspace.net.au on 11/26/2013



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




Re: Regrex Question

2013-11-25 Thread timothy adigun
Hi,

On Mon, Nov 25, 2013 at 7:55 PM, Mike Blezien wrote:

>  Hello,
>
> Regular expression have never been my strong suite
>
You might have to make it one. :)

> so hoping to get a litte help with a line in file I need to extract a
> portion of it.
>
> The text I need to extract from this line is "*November 21, 2013"* from
> this line in the file, just the date:
>
> Posted by  href="mailto:someem...@email.com";>SomeName 
> on*
> November 21, 2013* at 23:21:58:
>
> what would be the regrex to use to extract the date from the line ?
>
   Something like this:
   [CODE]
use warnings;
use strict;

 $_ = 'Posted by mailto:someem...@email.com";>Some Name on
November 21, 2013 at 23:21:58:';
print $1 if(/.+on(.+)at/);
   [/CODE]

  You might have to read http://perldoc.perl.org/perlre.html for in depth
documentstion.

>
> Thanks,
>
> Mike(mickalo)Blezien
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Thunder Rain Internet Publishing
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>



-- 
Tim


Regrex Question

2013-11-25 Thread Mike Blezien
Hello,

Regular expression have never been my strong suite so hoping to get a litte 
help with a line in file I need to extract a portion of it.

The text I need to extract from this line is "November 21, 2013" from this line 
in the file, just the date:

Posted by mailto:someem...@email.com";>Some Name on November 21, 
2013 at 23:21:58:

what would be the regrex to use to extract the date from the line ?

Thanks,

Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Re: question about perl 6 sigils

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

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

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

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


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




Re: question about perl 6 sigils

2013-09-24 Thread Octavian Rasnita
From: Andy Bach 


  On Tue, Sep 24, 2013 at 10:44 AM, Shawn H Corey  wrote:



There is also a third group who want to get rid of sigils entirely. ;)

  Ahhh! Blasphemy, Blasphemer! That way lies chaos! Dogs and cats, living 
together! NEVER!


  ... And I was going to add that there is a fourth group that already switched 
to Python. :-)

  Octavian


Re: question about perl 6 sigils

2013-09-24 Thread Luca Ferrari
On Tue, Sep 24, 2013 at 5:27 PM, Andy Bach  wrote:

> Did you read the exegesis? Damian is one of the smartest guys you'll ever
> hear speak (his book "Perl Best Practices", for one, is worth it's weight in
> classrooms - er, something like that).  It's not that you're wrong or that
> the argument that the sigil switch isn't useful, it's just not going to be
> that way in P6.


I read both the book and the exegenis, it is only that it requires me
to think about the correct usage of sigils because it is not as much
intuitive for me as it is in v5.
I was just trying to explain to my brain why having immutable sigils
is smarter than the v5 ones. I know Perl is built in a way everything
has a strong sense, I cannot see what is in this case.

Luca

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




Re: question about perl 6 sigils

2013-09-24 Thread Andy Bach
On Tue, Sep 24, 2013 at 10:44 AM, Shawn H Corey wrote:

>
> There is also a third group who want to get rid of sigils entirely. ;)
>

Ahhh! Blasphemy, Blasphemer! That way lies chaos! Dogs and cats, living
together! NEVER!

Er, sorry. As the exegesis are deprecated (though still worth the reads
just for the jokes) try also:
http://feather.perl6.nl/syn/Differences.html#Sigils
http://feather.perl6.nl/syn/S02.html#Sigils

for the modern-er docs.
-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: question about perl 6 sigils

2013-09-24 Thread Shawn H Corey
On Tue, 24 Sep 2013 10:27:24 -0500
Andy Bach  wrote:

> Did you read the exegesis? Damian is one of the smartest guys you'll
> ever hear speak (his book "Perl Best Practices", for one, is worth
> it's weight in classrooms - er, something like that).

Perl::Critic and its script, perlcritic, follow Damian's PBP. It's well
worth your time to install them and run your scripts thru them.

>  It's not that
> you're wrong or that the argument that the sigil switch isn't useful,
> it's just not going to be that way in P6.  There are many (as many?)
> folks happy about this as there are folks, like you, who think we're
> losing clarity.  Both have arguments and, as it happens, both
> arguments have proponents in the design of Perl committee (sometimes
> known as "@larry" ;-); only, for now, the sigil constancy crowd has
> one.  Maybe in P7 they'll've regained their sigils, er, senses.

There is also a third group who want to get rid of sigils entirely. ;)


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

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




Re: question about perl 6 sigils

2013-09-24 Thread Andy Bach
On Tue, Sep 24, 2013 at 3:43 AM, Luca Ferrari  wrote:

> What I don't understand here is why we have to keep the true
> sigil for any access.
>

Did you read the exegesis? Damian is one of the smartest guys you'll ever
hear speak (his book "Perl Best Practices", for one, is worth it's weight
in classrooms - er, something like that).  It's not that you're wrong or
that the argument that the sigil switch isn't useful, it's just not going
to be that way in P6.  There are many (as many?) folks happy about this as
there are folks, like you, who think we're losing clarity.  Both have
arguments and, as it happens, both arguments have proponents in the design
of Perl committee (sometimes known as "@larry" ;-); only, for now, the
sigil constancy crowd has one.  Maybe in P7 they'll've regained their
sigils, er, senses.


-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: question about perl 6 sigils

2013-09-24 Thread Luca Ferrari
On Tue, Sep 24, 2013 at 12:52 AM, Andy Bach  wrote:
> I liked it, after I
> understood it.

I posted the question for the same reason: I believe that having the
sigil meaning what you (are thinking) you are accessing was a great
idea. What I don't understand here is why we have to keep the true
sigil for any access. Let's say that if I write something like:

$a[0]

it is quite clear to me that I'm accessing an array, so I don't see why

@a[0]

will give me more info.
The same seems true for me for hashes.

Luca

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




Re: question about perl 6 sigils

2013-09-23 Thread Andy Bach
On Mon, Sep 23, 2013 at 10:17 AM, Luca Ferrari wrote:

>
It's just one of those things. When Perl was invented, Larry Wall liked the
idea of make the sigil mean something and mutate when the access did. Most
other languages (that had sigils) didn't do that.  Some people said
"genius" some people weren't too thrilled but it was Perl ... I liked it,
after I understood it.

But now - here, ask Damian (search for sigil)
http://www.perl.com/pub/2001/05/08/exegesis2.html


-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


  1   2   3   4   5   6   7   8   9   10   >