Re: Perl script: where was I executed from?

2020-11-22 Thread Vlado Keselj
Hi,

I am not sure that I completely understand your question (for example,
what does it mean to run a script "dynamically or not").  You could
retrieve the list of processes from OS to try to figure out how was the
script ran, but it is a bit messy.  Just maybe: maybe you want to see
whether the script is printing to a terminal or not and which terminal.
For example, something like:

 if (-t STDOUT) { print "this is tty\n" }
 else   { print "not tty\n" }

will give different output when you run directly in terminal, or if you
redirect the standard output to a file.


On Sat, 21 Nov 2020, wagsworld48 via beginners wrote:

> The only problem I was trying to determine was could i know if I was running 
> from BBEdit dynamically or not? That
> was the question. No problem, just could I know what environment I was 
> running in. The output was a the Unix output
> log which up to the last update automatically came to the front of the BBEdit 
> windows. No longer does. Whether it is
> Perl or another scripting language, I was trying to make it easier as one 
> tested.
> 
> So that is what I was after... ;)
> 
> WagsWorld World of Perl
> Hebrews 4:15
> Ph D:(408)914-1341
> Ph M:(408)761-7391
> On Nov 21, 2020, 21:10 -0800, Uri Guttman , wrote:
>   On 11/21/20 10:32 PM, wagsworl...@yahoo.com wrote:
> Well, up until this last update is BBEdit, when a script was run 
> while
> in BBEdit, the Unix log file would automatically come to the fore
> front. Now it stays hidden.
> 
> 
>   that doesn't sound like a perl problem. what log file? there are many on
>   a unix system. and why/how would a log file come to the front? it would
>   have to be open in some program.
> 
> A gentleman on the BBEdit mail list gave an   osasctipt that one 
> can
> execute from within the script bring executed. But sometimes I run
> from terminal session, so don’t want to tell BBEdit to do 
> something is
> not required. Hence where am I and from that know what to do...
> 
>   again, i don't see the actual problem you are having. is it really a
>   perl issue? would the problem exist if you did your program in another
>   language? that is a good question to determine if it is a language vs
>   system issue. i don't see a perl problem in your comments.
> 
>   thanx,
> 
>   uri
> 
> 
> 
-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Re: Perl script: where was I executed from?

2020-11-21 Thread Uri Guttman

On 11/22/20 12:33 AM, wagsworl...@yahoo.com wrote:
The only problem I was trying to determine was could i know if I was 
running from BBEdit dynamically or not? That was the question. No 
problem, just could I know what environment I was running in. The 
output was a the Unix output log which up to the last update 
automatically came to the front of the BBEdit windows. No longer does. 
Whether it is Perl or another scripting language, I was trying to make 
it easier as one tested.
that still is an XY problem. you are asking for X (know where perl is 
being spawned) when your actual problem is Y (getting the log file to 
pop up). they are not the same problem. if you just need to see the log 
file, run a tail -f command in a shell window and it will show you all 
the new log stuff as it happens. that is not a perl problem.


thanx,

uri

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




Re: Perl script: where was I executed from?

2020-11-21 Thread wagsworld48 via beginners
The only problem I was trying to determine was could i know if I was running 
from BBEdit dynamically or not? That was the question. No problem, just could I 
know what environment I was running in. The output was a the Unix output log 
which up to the last update automatically came to the front of the BBEdit 
windows. No longer does. Whether it is Perl or another scripting language, I 
was trying to make it easier as one tested.

So that is what I was after... ;)

WagsWorld
World of Perl
Hebrews 4:15
Ph D:(408)914-1341
Ph M:(408)761-7391
On Nov 21, 2020, 21:10 -0800, Uri Guttman , wrote:
> On 11/21/20 10:32 PM, wagsworl...@yahoo.com wrote:
> > Well, up until this last update is BBEdit, when a script was run while
> > in BBEdit, the Unix log file would automatically come to the fore
> > front. Now it stays hidden.
> >
>
> that doesn't sound like a perl problem. what log file? there are many on
> a unix system. and why/how would a log file come to the front? it would
> have to be open in some program.
>
> > A gentleman on the BBEdit mail list gave an   osasctipt that one can
> > execute from within the script bring executed. But sometimes I run
> > from terminal session, so don’t want to tell BBEdit to do something is
> > not required. Hence where am I and from that know what to do...
> again, i don't see the actual problem you are having. is it really a
> perl issue? would the problem exist if you did your program in another
> language? that is a good question to determine if it is a language vs
> system issue. i don't see a perl problem in your comments.
>
> thanx,
>
> uri
>


Re: Perl script: where was I executed from?

2020-11-21 Thread Uri Guttman

On 11/21/20 10:32 PM, wagsworl...@yahoo.com wrote:
Well, up until this last update is BBEdit, when a script was run while 
in BBEdit, the Unix log file would automatically come to the fore 
front. Now it stays hidden.




that doesn't sound like a perl problem. what log file? there are many on 
a unix system. and why/how would a log file come to the front? it would 
have to be open in some program.


A gentleman on the BBEdit mail list gave an   osasctipt that one can 
execute from within the script bring executed. But sometimes I run 
from terminal session, so don’t want to tell BBEdit to do something is 
not required. Hence where am I and from that know what to do...
again, i don't see the actual problem you are having. is it really a 
perl issue? would the problem exist if you did your program in another 
language? that is a good question to determine if it is a language vs 
system issue. i don't see a perl problem in your comments.


thanx,

uri

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




Re: Perl script: where was I executed from?

2020-11-21 Thread wagsworld48 via beginners
Well, up until this last update is BBEdit, when a script was run while in 
BBEdit, the Unix log file would automatically come to the fore front. Now it 
stays hidden.

A gentleman on the BBEdit mail list gave an   osasctipt that one can execute 
from within the script bring executed. But sometimes I run from terminal 
session, so don’t want to tell BBEdit to do something is not required. Hence 
where am I and from that know what to do...

Thoughts??? ;)

WagsWorld
World of Perl
Hebrews 4:15
Ph D:(408)914-1341
Ph M:(408)761-7391
On Nov 21, 2020, 18:09 -0800, Uri Guttman , wrote:
> On 11/21/20 7:42 PM, wagsworld48 via beginners wrote:
> > It was a good idea, but that gives me zsh which is what in this case
> > BBEdit uses to execute the script. So with your code of $ENV, then I
> > looked at the variables within ENV and picked one that was there for
> > BBEdit and not there in a normal terminal run. Know other ways, but
> > this at least is one way to accomplish the task..
> ok, i am smelling an XY problem here. why do you need to know from where
> the perl was executed? in general processes don't know the path of their
> parent process. one way around this is to pass a special value to the
> perl process (via argument or env) that tells the perl of its origin.
>
> but a bigger question is, why do you need/want to know this? what
> difference will it make to the perl process?
>
> thanx,
>
> uri
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>


Re: Perl script: where was I executed from?

2020-11-21 Thread Uri Guttman

On 11/21/20 7:42 PM, wagsworld48 via beginners wrote:
It was a good idea, but that gives me zsh which is what in this case 
BBEdit uses to execute the script. So with your code of $ENV, then I 
looked at the variables within ENV and picked one that was there for 
BBEdit and not there in a normal terminal run. Know other ways, but 
this at least is one way to accomplish the task..
ok, i am smelling an XY problem here. why do you need to know from where 
the perl was executed? in general processes don't know the path of their 
parent process. one way around this is to pass a special value to the 
perl process (via argument or env) that tells the perl of its origin.


but a bigger question is, why do you need/want to know this? what 
difference will it make to the perl process?


thanx,

uri

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




Re: Perl script: where was I executed from?

2020-11-21 Thread wagsworld48 via beginners
It was a good idea, but that gives me zsh which is what in this case BBEdit 
uses to execute the script. So with your code of $ENV, then I looked at the 
variables within ENV and picked one that was there for BBEdit and not there in 
a normal terminal run. Know other ways, but this at least is one way to 
accomplish the task..

Thanks much for getting the mind going. I appreciate the thought and it did 
help... ;)

WagsWorld
World of Perl
Hebrews 4:15
Ph D:(408)914-1341
Ph M:(408)761-7391
On Nov 21, 2020, 16:03 -0800, sisyphus , wrote:
> Perhaps:
> perl -le 'print $ENV{SHELL}'
>
> Cheers,
> Rob
>
> > On Sun, Nov 22, 2020 at 8:00 AM wagsworld48 via beginners 
> >  wrote:
> > > Mind is blank, but want to know if started with say BBEdit or bash or ?
> > >
> > > Probably very simple, but at this point, no idea... ;)
> > >
> > > WagsWorld
> > > World of Perl
> > > Hebrews 4:15
> > > Ph D:(408)914-1341
> > > Ph M:(408)761-7391


Re: Perl script: where was I executed from?

2020-11-21 Thread sisyphus
Perhaps:
perl -le 'print $ENV{SHELL}'

Cheers,
Rob

On Sun, Nov 22, 2020 at 8:00 AM wagsworld48 via beginners <
beginners@perl.org> wrote:

> Mind is blank, but want to know if started with say BBEdit or bash or ?
>
> Probably very simple, but at this point, no idea... ;)
>
> WagsWorld
> World of Perl
> Hebrews 4:15
> Ph D:(408)914-1341
> Ph M:(408)761-7391
>


Perl script: where was I executed from?

2020-11-21 Thread wagsworld48 via beginners
Mind is blank, but want to know if started with say BBEdit or bash or ?

Probably very simple, but at this point, no idea... ;)

WagsWorld
World of Perl
Hebrews 4:15
Ph D:(408)914-1341
Ph M:(408)761-7391


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











--

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

perl script problem

2019-10-13 Thread 刘东
Dear every one,
I have written a perl script to get seprated files, but finally I every file 
included multiple files appeared before,
for example, 1 file 2M, 2 file 5 M( included last one), 3 file 6 M (included 
last two ones), ...
but I expected as 1 file 2M, 2 file 3M, 3 file 1 M, ...
the script as follows:
#! /usr/bin/perl

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

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

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

foreach $files (glob("$dir/*.txt")) {
  ($file_dir, $file_main) = split (/\/\//,$files);
  ($file_name,$file_format) =split(/\./,$file_main);
  $outfile= $file_name."_sg.txt";
 
open OUT,">",$outfile or die "can't open $outfile";
open IN,"<$files" or die "can't read open $files";

while(defined (my $line= )){
chomp($line);
$line =~s/^\s+//g;
next if ($line =~ m/^S*$/);
my ($id,$start,$end)= (split /\t/,$line)[0,1,2]; # no 3 after "split /\t/,$line"
my $m_lenth = $end-$start+1;
   
if (exists $hash{$id}) {
my ($start,$end)= (split /\t/,$hash{$id})[1,2];
if ($m_lenth > ($end-$start+1)) {
$hash{$id} = $line;
}
} else {
$hash{$id} = $line;
}
  }
 
my @val = values %hash;
print OUT "@val\n";

close OUT;
close IN;
}







--

Hunan Normal University, Changsha, China:Dong Liu

 
格言:积土而为山,积水而为海;
知识在于积累,成功在于勤奋。




 

Re: perl script with wrong

2019-10-13 Thread Jim Gibson



> On Oct 10, 2019, at 6:04 PM, 刘东  wrote:
> 
> Dear friends,
> I have written a perl script to get seprated files, but finally I every file 
> included multiple files appeared before,
> for example, 1 file 2M, 2 file 5 M( included last one), 3 file 6 M (included 
> last two ones), ...
> but I expected as 1 file 2M, 2 file 3M, 3 file 1 M, …

You are adding data to %hash for each file read. Since %hash is global, it will 
contain all of the data from the current file and all previously read files.

If you want to start with an empty hash for each file, then declare %hash 
inside of the foreach loop or assign %hash to () at the beginning of the 
foreach loop.

> the script as follows:
> #! /usr/bin/perl
> 
> use strict;
> use warnings;
> use Getopt::Long;
> 
> my ($dir, $files, $file_dir, $file_name, $file_main, $file_format, $outfile);
> my %hash;
> 
> GetOptions ('dr=s'  =>\$dir);
> 
> foreach $files (glob("$dir/*.txt")) {
>   ($file_dir, $file_main) = split (/\/\//,$files);
>   ($file_name,$file_format) =split(/\./,$file_main);
>   $outfile= $file_name."_sg.txt";
>   
> open OUT,">",$outfile or die "can't open $outfile";
> open IN,"<$files" or die "can't read open $files";
> 
> while(defined (my $line= )){
> chomp($line);
> $line =~s/^\s+//g;
> next if ($line =~ m/^S*$/);
> my ($id,$start,$end)= (split /\t/,$line)[0,1,2]; # no 3 after "split 
> /\t/,$line"
> my $m_lenth = $end-$start+1; 
> 
> if (exists $hash{$id}) { 
> my ($start,$end)= (split /\t/,$hash{$id})[1,2]; 
> if ($m_lenth > ($end-$start+1)) { 
> $hash{$id} = $line;
> }
> } else { 
> $hash{$id} = $line; 
> }
>   }
>   
> my @val = values %hash;
> print OUT "@val\n"; 
> 
> close OUT;
> close IN;
> }
> 
> 
> 
> 
> 
> --
> Hunan Normal University, Changsha, China:Dong Liu
>  
> 格言:积土而为山,积水而为海;
> 知识在于积累,成功在于勤奋。
> 
> 
>  

Jim Gibson
j...@gibson.org

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




perl script with wrong

2019-10-13 Thread 刘东
Dear friends,
I have written a perl script to get seprated files, but finally I every file 
included multiple files appeared before,
for example, 1 file 2M, 2 file 5 M( included last one), 3 file 6 M (included 
last two ones), ...
but I expected as 1 file 2M, 2 file 3M, 3 file 1 M, ...
the script as follows:
#! /usr/bin/perl

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

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

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

foreach $files (glob("$dir/*.txt")) {
  ($file_dir, $file_main) = split (/\/\//,$files);
  ($file_name,$file_format) =split(/\./,$file_main);
  $outfile= $file_name."_sg.txt";
 
open OUT,">",$outfile or die "can't open $outfile";
open IN,"<$files" or die "can't read open $files";

while(defined (my $line= )){
chomp($line);
$line =~s/^\s+//g;
next if ($line =~ m/^S*$/);
my ($id,$start,$end)= (split /\t/,$line)[0,1,2]; # no 3 after "split /\t/,$line"
my $m_lenth = $end-$start+1;
   
if (exists $hash{$id}) {
my ($start,$end)= (split /\t/,$hash{$id})[1,2];
if ($m_lenth > ($end-$start+1)) {
$hash{$id} = $line;
}
} else {
$hash{$id} = $line;
}
  }
 
my @val = values %hash;
print OUT "@val\n";

close OUT;
close IN;
}







--

Hunan Normal University, Changsha, China: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: How to get a called perl script to write output to a file with DIFFERENT user:group than the calling app?

2017-01-16 Thread Chris Fedde
Other comments on this question discuss elevating user permissions via
suid, sudo the setuid bit and so on.
There are good reasons to need to create files with owner/group that are
different from your own, they usually come up in system administration
situations.  Most common situation where access sharing come up can be
handled with the way linux group membership works and use of the setgid bit
on directories.

If "appuser" is a member of "othergroup" and the directory where the script
will write the file is setgid "othergroup" then when the script writes the
file it will have group "othergroup".  Usually this is sufficient.

Of course this assumes linux and other things sufficiently unix like.

On Sun, Jan 15, 2017 at 3:45 PM, <al...@myfastmail.com> wrote:

> I have an application that calls a perl script, feeding it input over
> STDIN.
>
> The perl script takes that input, processes it, and writes is as a change
> to an output file.
>
> I use Path::Tiny, and this works ok,
>
> use Path::Tiny qw(path);
>
> my $newdata = $@;
> $newdata = (some processing);
>
> my $file = path('/home/aj/out.txt');
> my $data = $file->slurp_utf8;
> $data =~ s/some label.*/${1} $newdata} ]/x;
> $file->spew_utf8( $data );
>
> The app runs as
>
> USER  = "appuser"
> GROUP = "appgroup"
>
> and the perl-script's output file gets CHANGED to ownership by the SAME
> user & group, 'appuser'/'appgroup'.
>
> How do I get that output file written with owndership by some OTHER user,
> eg
>
> USER  = "otheruser"
> GROUP = "othergroup"
>
> ?
>
> AJ
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: How to get a called perl script to write output to a file with DIFFERENT user:group than the calling app?

2017-01-15 Thread Chas. Owens
snip

> So I guess the question is -
>
> - is there a way in perl to authorize the callED perl script to have
> higher perms than the callING app's, so that it can write to the file I'm
> targeting?
>
> Or do I have to to this OUTSIDE of the perl script?
>

The short answer is that this is OS dependent. The longer answer is in
Linux, only if the script is running as root (directly, through suid, or
via sudo) and you probably don't want to do that. A better question is the
script is writing to a file owned by a different user.  That is outside of
the normal way of doing things in UNIX.


Re: How to get a called perl script to write output to a file with DIFFERENT user:group than the calling app?

2017-01-15 Thread alanj
> Is that your real program

Close, but copied from my (changing) notes, not from the actual code.  See 
below.

> but changing something to the same data amounts to it being *unchanged*, 
> surely?

Nope.  Not using Path::Tiny.

I found the info I need buried a further donw on its webpage.  Apparently the 
default IS to change the file to the running user's umask.

The webpage says

NOTE: because the file is written to a temporary file and then renamed, 
the new file will wind up with permissions based on your current umask. This is 
a feature to protect you from a race condition that would otherwise give 
different permissions than you might expect. If you really want to keep the 
original mode flags, use "append" with the truncate option.


I was using

$file->spew_utf8( $data );

So I changed that to

$file->append_utf8( { truncate => 1 }, $data );

and now it leaves the perms alone.

And it writes successfully *IF* the calling app's/user's perms are higher than 
the target file's.  Which is where I'm stuck a bit.

Unless there's something IN perl, I think maybe sudoers is what I need to fuss 
with.  Not sure yet.

> Can you please show your real program and data input, together with the 
> output you want? We will also need to understand what parameters are being 
> passed to your program, and where it gets the new values for user and group.

Here's the latest, current script

#!/usr/bin/perl

use 5.01201;
use strict;
use warnings;
use Path::Tiny qw(path);

my $var1 = shift;
my $outfile = '/home/aj/out.txt';
my @alldirs = qw(
/path/1
/path/2
);
my $var2 = "testing123";

my_usr = 'aj';
my_grp = 'users';

sub s_modify {

my %args  = %{ shift @_ };

my $fn   = $args{FN};
my $ar   = $args{AR};
my $di   = $args{DI};
my @dd = @{$args{DD};

foreach (@dd) {
my $dir = $_;
my $file = path($dir . "/" . $fn);
my $data = $file->slurp_utf8;
$data =~ s|(^$ar).*|${1} this was modified|;
$file->append_utf8( { truncate => 1 }, $data );
}
return;
}

s_modify (
 {
   FN => $outfile,
   DD => \@alldirs,
   AR => $var2,
   DI => $var1
 }
);

}

So the calling app is running as

USER  = 'appuser'
GROUP = 'appgroup'

It calls my script, passing only one piece of scalar data to it:

$var1

My script then targets the output file

my $outfile = '/home/aj/out.txt';

where

ls -al /home/aj/out.txt
-rw--- 1 aj users  31K Jan 15  2017 /home/aj/out.txt

It searches/matches the line in it that

testing123 some other text

and changes it to

testing123 this was modified

If

'appuser' == 'root'
'appgroup' == 'root'

i.e. the calling app's running perms are greater than aj:users, the change is 
made,

and, afterward, the file's perms are the same as they were before

ls -al /home/aj/out.txt
-rw--- 1 aj users  31K Jan 15  2017 /home/aj/out.txt

But if the calling app's running as a unique user

'appuser'  == 'testapp'
'appgroup' == 'testapp'

where

id testapp
uid=12345(testapp) gid=12345(testapp) groups=12345(testapp)
grep testapp /etc/group
testapp:x:12345:

the changes don't get made; the target file is untouched.

So I guess the question is -

- is there a way in perl to authorize the callED perl script to have higher 
perms than the callING app's, so that it can write to the file I'm targeting?

Or do I have to to this OUTSIDE of the perl script?

AJ

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




Re: How to get a called perl script to write output to a file with DIFFERENT user:group than the calling app?

2017-01-15 Thread Rob Dixon
Hi

Is that your real program, because it's rather odd?

The built-in variable `$@` holds the message from the latest error to be 
trapped by `eval`, so since you have no `eval` blocks it will probably be 
`undef`. Did you mean to assign the command-line parameter, like this?

my ($newdata) = @ARGV;

Also, your substitution

$data =~ s/some label.*/${1} $newdata} ]/x;

uses the capture variable `$1` in the replacement string, but there are no 
captures in your regular expression, so it is likely to also be `undef`. It's 
worth pointing out that the "extended syntax" modifier `/x` allows you to add 
insignificant whitespace to your regex pattern so that you can make it more 
readable, but you have no spaces in this case so it's not doing anything 
useful; it won't do any harm, though.

You appear to want to change the values of the `USER` and `GROUP` items in the 
config file `out.txt`, but it's far from clear where your new values come from. 
Are they both in `$newdata` somehow? And how do you imagine your program will 
make two unrelated  changes with only a single substitution?

You say

> output file gets CHANGED to ownership by the SAME user & group

but changing something to the same data amounts to it being *unchanged*, surely?

Can you please show your real program and data input, together with the output 
you want? We will also need to understand what parameters are being passed to 
your program, and where it gets the new values for user and group.

Thanks.

Rob Dixon



On 15 January 2017 22:45:43 GMT+00:00, al...@myfastmail.com wrote:
>I have an application that calls a perl script, feeding it input over
>STDIN.
>
>The perl script takes that input, processes it, and writes is as a
>change to an output file.
>
>I use Path::Tiny, and this works ok,
>
>   use Path::Tiny qw(path);
>
>   my $newdata = $@;
>   $newdata = (some processing);
>
>   my $file = path('/home/aj/out.txt');
>   my $data = $file->slurp_utf8;
>   $data =~ s/some label.*/${1} $newdata} ]/x;
>   $file->spew_utf8( $data );
>
>The app runs as
>
>   USER  = "appuser"
>   GROUP = "appgroup"
>
>and the perl-script's output file gets CHANGED to ownership by the SAME
>user & group, 'appuser'/'appgroup'.
>
>How do I get that output file written with owndership by some OTHER
>user, eg
>
>   USER  = "otheruser"
>   GROUP = "othergroup"
>
>?
>
>AJ
>
>-- 
>To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>For additional commands, e-mail: beginners-h...@perl.org
>http://learn.perl.org/

-- 
Sent from Kaiten Mail. Please excuse my brevity.

How to get a called perl script to write output to a file with DIFFERENT user:group than the calling app?

2017-01-15 Thread alanj
I have an application that calls a perl script, feeding it input over STDIN.

The perl script takes that input, processes it, and writes is as a change to an 
output file.

I use Path::Tiny, and this works ok,

use Path::Tiny qw(path);

my $newdata = $@;
$newdata = (some processing);

my $file = path('/home/aj/out.txt');
my $data = $file->slurp_utf8;
$data =~ s/some label.*/${1} $newdata} ]/x;
$file->spew_utf8( $data );

The app runs as

USER  = "appuser"
GROUP = "appgroup"

and the perl-script's output file gets CHANGED to ownership by the SAME user & 
group, 'appuser'/'appgroup'.

How do I get that output file written with owndership by some OTHER user, eg

USER  = "otheruser"
GROUP = "othergroup"

?

AJ

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




Re: perl script with errors?

2015-11-26 Thread Shlomi Fish
Hi Jin,

some comments on your code:

On Thu, 26 Nov 2015 08:13:54 +0800
Jin Xu  wrote:

> Try to use below updated ones:
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> while (my $line = <>) {

You're lacking many empty lines - separating the code into paragraphs. See:

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

> while ($line =~
> s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*##) {
> my $result;
> eval ("$result = $&;");

There's no need for string eval here and with interpolating double-quotes, it
won't do the right thing:

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

Just do:

 my $result = $&;

Or if you really must:

my $result;
eval
{
$result = $&;
};
if ($@)
{


Furthermore , the use of $& and friends is not advised:

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


> $line =~ s//$result/;
> 

this can be combined into a single s/// statement.



> }
> print ($line);
> }
> 
> 
> 
> Regards,
> Jin Xu
> 
> 

Regards,

Shlomi Fish



-- 
-
Shlomi Fish

Please reply to list if it's a mailing list post .

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




Re: perl script with errors?

2015-11-26 Thread Shlomi Fish
Hi Miguel,

On Wed, 25 Nov 2015 20:28:48 -0500
Miguel Rodas  wrote:

> Why am I in this thread?
> 
> Please remove me from it
> 

You are likely subscribed to beginners@perl.org and so receive all E-mails from
all threads. For how to unsubscribe, see
http://learn.perl.org/faq/beginners.html .

Regards,

Shlomi Fish

> Sent from my iPhone
> 

-- 
-
Shlomi Fish

Please reply to list if it's a mailing list post

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




Re: perl script with errors?

2015-11-25 Thread Rui Fernandes
Hi Gary,

I don't know what you are trying to do with that code... :( Still, it's
valid this way:

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

print "Content-type: text/html\n\n"; #Only if you want this format

while (my $line = <>) {
while ($line =~ s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*##) {
my $result = eval ("$&;");
$line =~ s//$result/;

}
print ($line);
}

If you input, for instance, 23*2 you'll get 46.

Does this help?

Kind regards,

Este
e-mail foi enviado a partir de um computador sem vírus protegido pela
Avast.
www.avast.com

<#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Wed, Nov 25, 2015 at 3:18 PM, Olivier Le Monnier <
olivier.lemonn...@unicaen.fr> wrote:

> > gb@MINT ~/Perl5/perl programs $ cat prog164.pl
> > #!/usr/bin/perl
> > use strict;
> > use warnings;
> > while ($line = <>) {
> > while ($line =~
> > s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*##) {
> > eval ("\$result = $&;");
> > $line =~ s//$result/;
> >
> > }
> > print ($line);
> > }
> >
> >
> >
> > gb@MINT ~/Perl5/perl programs $ ./prog164.pl
> > Global symbol "$line" requires explicit package name at ./prog164.pl
> line 4.
> > Global symbol "$line" requires explicit package name at ./prog164.pl
> line 5.
> > Global symbol "$line" requires explicit package name at ./prog164.pl
> line 8.
> > Global symbol "$result" requires explicit package name at ./prog164.pl
> line
> > 8.
> > Global symbol "$line" requires explicit package name at ./prog164.pl
> line
> > 11.
> > Execution of ./prog164.pl aborted due to compilation errors.
> > gb@MINT ~/Perl5/perl programs $
> >
> >
> > What is this error? And what am I doing wrong.
>
>   Using strict mode, you should declare the variables scope with my for
> example…
>
> --
> Olivier Le Monnier — ☎ 023156.6209
> Administrateur systèmes libre(s)
> Direction du Système d'Information
> Université de Caen Normandie
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 


*Rui Miguel Fernandes*
*Porto - Portugal*



*Website: Cosmos - Portal Interactivo de Astronomia / Interactive Gate of
Astronomyhttp://www.cosmos.pt *


Re: perl script with errors?

2015-11-25 Thread Olivier Le Monnier
> gb@MINT ~/Perl5/perl programs $ cat prog164.pl
> #!/usr/bin/perl
> use strict;
> use warnings;
> while ($line = <>) {
> while ($line =~
> s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*##) {
> eval ("\$result = $&;");
> $line =~ s//$result/;
> 
> }
> print ($line);
> }
> 
> 
> 
> gb@MINT ~/Perl5/perl programs $ ./prog164.pl
> Global symbol "$line" requires explicit package name at ./prog164.pl line 4.
> Global symbol "$line" requires explicit package name at ./prog164.pl line 5.
> Global symbol "$line" requires explicit package name at ./prog164.pl line 8.
> Global symbol "$result" requires explicit package name at ./prog164.pl line
> 8.
> Global symbol "$line" requires explicit package name at ./prog164.pl line
> 11.
> Execution of ./prog164.pl aborted due to compilation errors.
> gb@MINT ~/Perl5/perl programs $
> 
> 
> What is this error? And what am I doing wrong.

  Using strict mode, you should declare the variables scope with my for example…

-- 
Olivier Le Monnier — ☎ 023156.6209 
Administrateur systèmes libre(s) 
Direction du Système d'Information 
Université de Caen Normandie 


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




Re: perl script with errors?

2015-11-25 Thread Jin Xu
Try to use below updated ones:

#!/usr/bin/perl
use strict;
use warnings;
while (my $line = <>) {
while ($line =~
s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*##) {
my $result;
eval ("$result = $&;");
$line =~ s//$result/;

}
print ($line);
}



Regards,
Jin Xu



2015-11-25 23:09 GMT+08:00 Gary Baker :

> gb@MINT ~/Perl5/perl programs $ cat prog164.pl
> #!/usr/bin/perl
> use strict;
> use warnings;
> while ($line = <>) {
> while ($line =~
> s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*##) {
> eval ("\$result = $&;");
> $line =~ s//$result/;
>
> }
> print ($line);
> }
>
>
>
> gb@MINT ~/Perl5/perl programs $ ./prog164.pl
> Global symbol "$line" requires explicit package name at ./prog164.pl line
> 4.
> Global symbol "$line" requires explicit package name at ./prog164.pl line
> 5.
> Global symbol "$line" requires explicit package name at ./prog164.pl line
> 8.
> Global symbol "$result" requires explicit package name at ./prog164.pl
> line 8.
> Global symbol "$line" requires explicit package name at ./prog164.pl line
> 11.
> Execution of ./prog164.pl aborted due to compilation errors.
> gb@MINT ~/Perl5/perl programs $
>
>
> What is this error? And what am I doing wrong.
>


Re: perl script with errors?

2015-11-25 Thread Miguel Rodas
Why am I in this thread?

Please remove me from it

Sent from my iPhone

> On Nov 25, 2015, at 7:13 PM, Jin Xu  wrote:
> 
> Try to use below updated ones:
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> while (my $line = <>) {
> while ($line =~
> s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*##) {
> my $result;
> eval ("$result = $&;");
> $line =~ s//$result/;
> 
> }
> print ($line);
> }
> 
> 
> 
> Regards,
> Jin Xu
> 
> 
> 
> 2015-11-25 23:09 GMT+08:00 Gary Baker :
>> gb@MINT ~/Perl5/perl programs $ cat prog164.pl
>> #!/usr/bin/perl 
>> use strict;
>> use warnings;
>> while ($line = <>) {
>> while ($line =~
>> s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*##) {
>> eval ("\$result = $&;");
>> $line =~ s//$result/;
>> 
>> }
>> print ($line);
>> }
>> 
>> 
>> 
>> gb@MINT ~/Perl5/perl programs $ ./prog164.pl
>> Global symbol "$line" requires explicit package name at ./prog164.pl line 4.
>> Global symbol "$line" requires explicit package name at ./prog164.pl line 5.
>> Global symbol "$line" requires explicit package name at ./prog164.pl line 8.
>> Global symbol "$result" requires explicit package name at ./prog164.pl line 
>> 8.
>> Global symbol "$line" requires explicit package name at ./prog164.pl line 11.
>> Execution of ./prog164.pl aborted due to compilation errors.
>> gb@MINT ~/Perl5/perl programs $ 
>> 
>> 
>> What is this error? And what am I doing wrong.
> 


perl script with errors?

2015-11-25 Thread Gary Baker
gb@MINT ~/Perl5/perl programs $ cat prog164.pl
#!/usr/bin/perl
use strict;
use warnings;
while ($line = <>) {
while ($line =~
s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*##) {
eval ("\$result = $&;");
$line =~ s//$result/;

}
print ($line);
}



gb@MINT ~/Perl5/perl programs $ ./prog164.pl
Global symbol "$line" requires explicit package name at ./prog164.pl line 4.
Global symbol "$line" requires explicit package name at ./prog164.pl line 5.
Global symbol "$line" requires explicit package name at ./prog164.pl line 8.
Global symbol "$result" requires explicit package name at ./prog164.pl line
8.
Global symbol "$line" requires explicit package name at ./prog164.pl line
11.
Execution of ./prog164.pl aborted due to compilation errors.
gb@MINT ~/Perl5/perl programs $


What is this error? And what am I doing wrong.


Posting to WordPress from a Perl script?

2013-07-19 Thread Octavian Rasnita
Hi,

Do you know if there is a working module that can be used to post to WordPress 
from a Perl script? I've seen that all the modules that contain WordPress are 
very old.

I need to install that module under a Perl built with Perlbrew.
I tried to install WordPress, WordPress::API, but they both depend on 
WordPress::XMLRPC which depends on SOAP::Lite which depends on XML::Parser 
which can't be installed because of the error expat.h - no such file or 
directory.
I also tried to install XML::Parser::Expat but it gives the same error.

By curiosity I searched for a Python module, and I found 
python-wordpress-xmlrpc, I installed it very fast and easy, I found that it 
offers more features than the Perl module WordPress, I tested a sample script I 
found on the web, and it worked very well.

The problem is that... I don't know Python.
(yet :)

--Octavian


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




Re: Posting to WordPress from a Perl script?

2013-07-19 Thread jbiskofski
If you can figure out the exact parameters that Wordpress normally posts
you can replicate those same parameters + cookie session information and it
should work.

Another nice alternative would be to look at the Mechanize CPAN modules.
Using Mechanize you can in perl code browse a web page, click links, fill
out forms and submit.

- Jose


On Fri, Jul 19, 2013 at 6:15 AM, Octavian Rasnita orasn...@gmail.comwrote:

 Hi,

 Do you know if there is a working module that can be used to post to
 WordPress from a Perl script? I've seen that all the modules that contain
 WordPress are very old.

 I need to install that module under a Perl built with Perlbrew.
 I tried to install WordPress, WordPress::API, but they both depend on
 WordPress::XMLRPC which depends on SOAP::Lite which depends on XML::Parser
 which can't be installed because of the error expat.h - no such file or
 directory.
 I also tried to install XML::Parser::Expat but it gives the same error.

 By curiosity I searched for a Python module, and I found
 python-wordpress-xmlrpc, I installed it very fast and easy, I found that it
 offers more features than the Perl module WordPress, I tested a sample
 script I found on the web, and it worked very well.

 The problem is that... I don't know Python.
 (yet :)

 --Octavian


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





Re: Posting to WordPress from a Perl script?

2013-07-19 Thread jbiskofski
Also, to fix the expat error you need to install libxml development
libraries, depending on your distro this can be accomplished in different
ways.


On Fri, Jul 19, 2013 at 12:07 PM, jbiskofski jbiskof...@gmail.com wrote:

 If you can figure out the exact parameters that Wordpress normally posts
 you can replicate those same parameters + cookie session information and it
 should work.

 Another nice alternative would be to look at the Mechanize CPAN modules.
 Using Mechanize you can in perl code browse a web page, click links, fill
 out forms and submit.

 - Jose


 On Fri, Jul 19, 2013 at 6:15 AM, Octavian Rasnita orasn...@gmail.comwrote:

 Hi,

 Do you know if there is a working module that can be used to post to
 WordPress from a Perl script? I've seen that all the modules that contain
 WordPress are very old.

 I need to install that module under a Perl built with Perlbrew.
 I tried to install WordPress, WordPress::API, but they both depend on
 WordPress::XMLRPC which depends on SOAP::Lite which depends on XML::Parser
 which can't be installed because of the error expat.h - no such file or
 directory.
 I also tried to install XML::Parser::Expat but it gives the same error.

 By curiosity I searched for a Python module, and I found
 python-wordpress-xmlrpc, I installed it very fast and easy, I found that it
 offers more features than the Perl module WordPress, I tested a sample
 script I found on the web, and it worked very well.

 The problem is that... I don't know Python.
 (yet :)

 --Octavian


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






Re: Posting to WordPress from a Perl script?

2013-07-19 Thread Octavian Rasnita
From: jbiskofski 
  Also, to fix the expat error you need to install libxml development 
libraries, depending on your distro this can be accomplished in different ways.

  Thanks. Finally I was able to install WordPress module and WordPress::API, 
but it was pretty hard.

  Octavian


Re: the perl script (SOLVED: sha-2 sum of files?)

2013-06-14 Thread Jim Gibson

On Jun 13, 2013, at 10:57 PM, lee wrote:

 Hi,
 
 so I've done this script now --- my fourth perl script ever --- and
 since I'm getting so much help here, I thought I'd post it here.  I'm
 sure it could be done much better, it's just plain and simple.
 
 It has one problem: The list of closed files can grow indefinitely, and
 since the script checks whether a file that has been closed is already
 listed, performance will degrade with the number of files on the closed
 list increasing.  This check isn't exactly needed and can be removed;
 other than that, I don't know (yet) what to do about that.

Some comments on your code:

1. Rather than doing this:

  while ( $curridx) {
chomp $_;
my $current_file = $_;

you should do this:

  while ( my $current_file = $curridx ) {
chomp($current_file);

2. I would return undef from gethash() if the file doesn't exist, rather than 
'~'. Undef is false in a logical test, and can also be tested with the define() 
function.

3. You are reading the close.list file for each file tested. It would be more 
efficient to read the close.list file and put the closed file names into a 
hash, and then you can test each file to see if it is in that hash, either with 
the exists() function, or just be testing the hash value. A hash evaluates to 
undef (false) if the key does not exist in the hash.

4. You can use the join(EXPR,LIST) function here:

  print $file $key . : . $size . : . $mtime . : . $hash . \n;

and do this instead:

print $file join(':',($key,$size,$mtime,$hash)), \n;



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




Re: the perl script (SOLVED: sha-2 sum of files?)

2013-06-14 Thread lee
Jim Gibson jimsgib...@gmail.com writes:

 Some comments on your code:

 1. Rather than doing this:

   while ( $curridx) { chomp $_; my $current_file = $_;

 you should do this:

   while ( my $current_file = $curridx ) { chomp($current_file);

Ah cool :)  I really didn't like the way I did that, this is much nicer
:)

 2. I would return undef from gethash() if the file doesn't exist,
 rather than '~'. Undef is false in a logical test, and can also be
 tested with the define() function.

H ... When you run

  perl -e 'if(undef == undef) {print eq\n;}'

it prints eq.  I don't know what

dbupdatehash($hashs_list_new, $current_file, $current_info[0],
 $current_info[1], gethash($current_file) );

would write into the hashs.list when gethash() returns undef.  I guess
it would fail with an error along the lines that an undefined value
cannot be printed (joined since I changed that) with others.


Working with non-existing files is actually a glitch in the script atm
because when gethash() returns '~' and that is put into the hashs.list,
next time when the non-existing file still doesn't exist, it may be
considered as changed again because dbreadhash() returns (-1, -1, )
either when the syntax is incorrect or the file isn't listed in the
hashs.list, and getinfo() returns (-100, -100) as an impossible file
size and impossible mtime.

That comes down to the script comparing a faked stored hash for the
non-existing file that looks like (-1, -1, ) with another faked hash
created for a non-existing file that looks like (-100, -100, ~).  The
non-existing file will then be considered as changed and reported.

Not knowing about 'undef', I did that intentional to work around the
problem of non-existing files letting the scipt fail when it comes
across them.  Maybe that was a bad idea.

So gethash(), getinfo() and dbreadhash() would have to return 'undef' in
some cases.  That breaks dbupdatehash(), so I'd have to check their
return values to skip non-existing files.  I should make the script
write its output to a logfile and make it read a configuration file
telling it which filenames to use to work with.

 3. You are reading the close.list file for each file tested. It would
 be more efficient to read the close.list file and put the closed file
 names into a hash, and then you can test each file to see if it is in
 that hash, either with the exists() function, or just be testing the
 hash value. A hash evaluates to undef (false) if the key does not
 exist in the hash.

Cool --- I'm reading up about such hashs now.  What if the closed.index
gets really large and needs to be kept in memory for this?

 4. You can use the join(EXPR,LIST) function here:

   print $file $key . : . $size . : . $mtime . : . $hash . \n;

 and do this instead:

 print $file join(':',($key,$size,$mtime,$hash)), \n;

sweet :)


-- 
Object-oriented programming languages aren't completely convinced that
you should be allowed to do anything with functions.
http://www.joelonsoftware.com/items/2006/08/01.html

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




the perl script (SOLVED: sha-2 sum of files?)

2013-06-13 Thread lee
Hi,

so I've done this script now --- my fourth perl script ever --- and
since I'm getting so much help here, I thought I'd post it here.  I'm
sure it could be done much better, it's just plain and simple.

It has one problem: The list of closed files can grow indefinitely, and
since the script checks whether a file that has been closed is already
listed, performance will degrade with the number of files on the closed
list increasing.  This check isn't exactly needed and can be removed;
other than that, I don't know (yet) what to do about that.

In any case, I come to really like perl :)




longbow.pl.gz
Description: application/gzip


-- 
Object-oriented programming languages aren't completely convinced that
you should be allowed to do anything with functions.
http://www.joelonsoftware.com/items/2006/08/01.html

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


Re: Perl Script for parsing log files.

2013-05-08 Thread Asad
Hi All ,

  Thanks to you all for the inputs . I have created the following
script :

use warnings;
use strict;
use File::Slurp qw(read_file);
use constant LIMIT = 3;## Number of lines wanted
use constant UPPERLIMIT = 9;

open (OUTFILE, '','d:\perl\OUTPUT.TXT');

#my $file = $ARGV[0];

my $filename = 'LOGFILE';

open(FH, '', $filename) or die $!;

my @lines = read_file($filename);

for ( 0 .. $#lines ) {
if ( $lines[$_] =~ m{\b(VERIFICATION_FAILED)\b}i ) {
 print $_\n;
 print $lines[$_];
   print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ + UPPERLIMIT
], $/;
}
elsif ($lines[$_] =~ m{\bfatal\b}i)
{
print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ +
UPPERLIMIT ], $/;
}
elsif ($lines[$_] =~ m{\b'Exception Severity: 1'\b})
{
print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ +
UPPERLIMIT ], $/;
}
elsif ($lines[$_] =~ m{\bstop\b}i)
{
print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ +
UPPERLIMIT ], $/;
}
elsif ($lines[$_] =~ m{\bfail\b}i)
{
print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ +
UPPERLIMIT ], $/;
}
else
{
print  No Errors found \n;
}

Please review if the above code seems ok .

Also want to know how to get this to UI(html page) interface for example a
html page which has a browse button to select the log file and it displays
the output parsing through the logic any module which this does or what you
suggest.

Any pointers for UI interface or any book I can refer would be helpful.


Thanks,



On Sat, Apr 13, 2013 at 9:20 PM, Asad asad.hasan2...@gmail.com wrote:

 Hi All ,

  Greetings !

I have completed O'Reily first book Learning Perl . Started writing
 small perl programs . However I basically do log file analysis , hence was
 thinking is there any perl code around in any of the book or if anyone
 already developed for the following requirement :

 Nowadays I manually read the log files to read the errors which are either
 fatal or warning or ignorable . The purpose is I want to develop a web page
 as in I upload this log file and it searches for those keywords (fatal or
 warning or ignorable) and if found those keywords display the 10line before
 it and after it .

 Please share your thoughts. Unable to start .

 Thanks,
 --
 Asad Hasan
 +91 9945666911




-- 
Asad Hasan
+91 9945666911


Re: Perl Script for parsing log files.

2013-05-08 Thread Ed Davis
Hi

My first contribution to the list!

Probably the simplest way to do this is (once you have apache2 installed and 
working) to create a script that looks a bit like this:

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

sub mylogparser {

Your script

}

mylogparser ();

print Content-type: text/html\n\n; #VERY IMPORTANT!!

print WEBPAGE;  #Start multiline variable which is just printed as HTML

all of your HTML goes here including reference to CSS etc and use $variables 
for dynamic content e.g your log data

WEBPAGE #note no semi colon

Your script will run on load so if you want to refresh it, maybe use a java 
script to do that. For pointers consider CGI but this will do what you are 
after.  Use a WYSIWYG editor to make it pretty and keep a copy to reuse :)

Hth.


On 8 May 2013, at 07:04, Asad asad.hasan2...@gmail.com wrote:

 Hi All ,
 
   Thanks to you all for the inputs . I have created the following 
 script :
 
 use warnings;
 use strict;
 use File::Slurp qw(read_file);
 use constant LIMIT = 3;## Number of lines wanted
 use constant UPPERLIMIT = 9;
 
 open (OUTFILE, '','d:\perl\OUTPUT.TXT');
 
 #my $file = $ARGV[0];
 
 my $filename = 'LOGFILE';
 
 open(FH, '', $filename) or die $!;
 
 my @lines = read_file($filename);
 
 for ( 0 .. $#lines ) {
 if ( $lines[$_] =~ m{\b(VERIFICATION_FAILED)\b}i ) {
print $_\n;
  print $lines[$_];
print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ + UPPERLIMIT 
 ], $/;
 }
   elsif ($lines[$_] =~ m{\bfatal\b}i)
   {
 print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ + UPPERLIMIT 
 ], $/;
   }
   elsif ($lines[$_] =~ m{\b'Exception Severity: 1'\b})
   {
 print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ + UPPERLIMIT 
 ], $/;
   }
   elsif ($lines[$_] =~ m{\bstop\b}i)
   {
 print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ + UPPERLIMIT 
 ], $/;
   }
   elsif ($lines[$_] =~ m{\bfail\b}i)
   {
 print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ + UPPERLIMIT 
 ], $/;
   }
   else 
   {
   print  No Errors found \n;
   }
 
 Please review if the above code seems ok .
 
 Also want to know how to get this to UI(html page) interface for example a 
 html page which has a browse button to select the log file and it displays 
 the output parsing through the logic any module which this does or what you 
 suggest.
 
 Any pointers for UI interface or any book I can refer would be helpful.
 
 
 Thanks,
 
 
 
 On Sat, Apr 13, 2013 at 9:20 PM, Asad asad.hasan2...@gmail.com wrote:
 Hi All ,
 
  Greetings !
 
I have completed O'Reily first book Learning Perl . Started writing 
 small perl programs . However I basically do log file analysis , hence was 
 thinking is there any perl code around in any of the book or if anyone 
 already developed for the following requirement :
 
 Nowadays I manually read the log files to read the errors which are either 
 fatal or warning or ignorable . The purpose is I want to develop a web page 
 as in I upload this log file and it searches for those keywords (fatal or 
 warning or ignorable) and if found those keywords display the 10line before 
 it and after it . 
 
 Please share your thoughts. Unable to start .
 
 Thanks,
 -- 
 Asad Hasan
 +91 9945666911
 
 
 
 -- 
 Asad Hasan
 +91 9945666911


Re: Perl Script for parsing log files.

2013-05-08 Thread Shlomi Fish
Hi Asad,

some comments on your script:

On Wed, 8 May 2013 11:34:14 +0530
Asad asad.hasan2...@gmail.com wrote:

 Hi All ,
 
   Thanks to you all for the inputs . I have created the following
 script :
 
 use warnings;
 use strict;
 use File::Slurp qw(read_file);
 use constant LIMIT = 3;## Number of lines wanted
 use constant UPPERLIMIT = 9;
 
 open (OUTFILE, '','d:\perl\OUTPUT.TXT');

1. Don't use bareword filehandles - use lexical ones instead.

2. Use autodie, or the or die thing:

http://perl-begin.org/tutorials/bad-elements/#open-function-style

 
 #my $file = $ARGV[0];
 
 my $filename = 'LOGFILE';
 
 open(FH, '', $filename) or die $!;

1. Don't use bareword filehandles.

2. Including a meaningful message in the die $!.

 
 my @lines = read_file($filename);
 
 for ( 0 .. $#lines ) {

Don't iterate using $_:

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

Use an explicit, lexical, iteration variable.

In recent perls, you can also use keys(@lines).

 if ( $lines[$_] =~ m{\b(VERIFICATION_FAILED)\b}i ) {

Use «(?: ... )» (for clustering) instead of «( ... )» (for capturing and in
this case, it is completely not-needed.

  print $_\n;
  print $lines[$_];
print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ + UPPERLIMIT
 ], $/;

MAke sure the upper and lower limits to the range are bounded.

 }
 elsif ($lines[$_] =~ m{\bfatal\b}i)
 {
 print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ +
 UPPERLIMIT ], $/;
 }
 elsif ($lines[$_] =~ m{\b'Exception Severity: 1'\b})
 {
 print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ +
 UPPERLIMIT ], $/;
 }
 elsif ($lines[$_] =~ m{\bstop\b}i)
 {
 print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ +
 UPPERLIMIT ], $/;
 }

1. You're using « $lines[$_] » too much - you should assign it to a variable.

2. There's a lot of duplicate code in the «print OUTFILE join   = '*',
@lines[ $_ - LIMIT .. $_ + UPPERLIMIT ], $/;»

 elsif ($lines[$_] =~ m{\bfail\b}i)
 {
 print OUTFILE join   = '*', @lines[ $_ - LIMIT .. $_ +
 UPPERLIMIT ], $/;
 }
 else
 {
 print  No Errors found \n;
 }
 
 Please review if the above code seems ok .

Hope it helped.

 
 Also want to know how to get this to UI(html page) interface for example a
 html page which has a browse button to select the log file and it displays
 the output parsing through the logic any module which this does or what you
 suggest.

You should write a module for that, and then use Dancer or whatever. See:

1. http://perl-begin.org/topics/modules-and-packages/

2. http://perl-begin.org/uses/web/

 
 Any pointers for UI interface or any book I can refer would be helpful.
 

The books are likely going to be out-of-date.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

Jack: Hi Sophie!
Sophie: Don’t “Hi, Sophie!” me.
Jack: Don’t “Don’t ‘Hi, Sophie!’ me” me!

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: Perl Script for parsing log files.

2013-04-14 Thread timothy adigun
Hi,

On Sat, Apr 13, 2013 at 4:50 PM, Asad asad.hasan2...@gmail.com wrote:

 Hi All ,

  Greetings !

I have completed O'Reily first book Learning Perl . Started writing
 small perl programs . However I basically do log file analysis , hence was
 thinking is there any perl code around in any of the book or if anyone
 already developed for the following requirement :

 Nowadays I manually read the log files to read the errors which are either
 fatal or warning or ignorable . The purpose is I want to develop a web page
 as in I upload this log file and it searches for those keywords (fatal or
 warning or ignorable) and if found those keywords display the 10line before
 it and after it .

 Please share your thoughts. Unable to start .



I agree with David, using a cache works very well.

But if your log files are not so large ( that I don't know :) ), you can
consider reading the file into an array ( of course, there are several
modules that does it for you, if you want ), then loop through the array,
once you get the line you wanted using regex, then take a range 10 lines
from and 10 lines to.

For Example:
[code]
use warnings;
use strict;
use File::Slurp qw(read_file);
use constant LIMIT = 3;## Number of lines wanted

my $file = $ARGV[0];

my @lines = read_file($file);

for ( 0 .. $#lines ) {
if ( $lines[$_] =~ m{^\s+?\b(it|mary|to)\b}i ) {
print join   = '*', @lines[ $_ - LIMIT .. $_ + LIMIT ], $/;
}
}
[/code]

ON the CLI:
Usage: perl_script.pl Mary_has_a_little_lamp_file.txt

You have to install the module `File::Slurp` if you don't have it.
You might also consider using  the module `Tie::File` this comes with your
Perl installation.




-- 
Tim


Perl Script for parsing log files.

2013-04-13 Thread Asad
Hi All ,

 Greetings !

   I have completed O'Reily first book Learning Perl . Started writing
small perl programs . However I basically do log file analysis , hence was
thinking is there any perl code around in any of the book or if anyone
already developed for the following requirement :

Nowadays I manually read the log files to read the errors which are either
fatal or warning or ignorable . The purpose is I want to develop a web page
as in I upload this log file and it searches for those keywords (fatal or
warning or ignorable) and if found those keywords display the 10line before
it and after it .

Please share your thoughts. Unable to start .

Thanks,
-- 
Asad Hasan
+91 9945666911


Re: Perl Script for parsing log files.

2013-04-13 Thread David Precious
On Sat, 13 Apr 2013 21:20:30 +0530
Asad asad.hasan2...@gmail.com wrote:

I have completed O'Reily first book Learning Perl . Started
 writing small perl programs . However I basically do log file
 analysis , hence was thinking is there any perl code around in any of
 the book or if anyone already developed for the following
 requirement :
 
 Nowadays I manually read the log files to read the errors which are
 either fatal or warning or ignorable . The purpose is I want to
 develop a web page as in I upload this log file and it searches for
 those keywords (fatal or warning or ignorable) and if found those
 keywords display the 10line before it and after it .
 
 Please share your thoughts. Unable to start .

At what point are you stuck?

Learning Perl should cover the basics you're describing - opening a
file, looping over it line by line, and checking if a line matches a
regular expression should all be quite easy for you.

(I would recommend working this out as a standalone script you run
locally to start with, and worry about the handling file uploads etc
afterwards, rather than trying to tackle it all at once.)

When you're looping over the file, you can easily keep the last 5 lines
in a buffer (use an array, push() a line to it each time, and if it
contains  5 lines, shift() the oldest off the front); when you find a
line that matches your pattern, print those five lines, then the line
you're processing, then the next 5.

What you're talking about sounds a lot like grep -C5 filename,
though - possible wheel re-invention :)

Cheers

Dave P


-- 
David Precious (bigpresh) dav...@preshweb.co.uk
http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook
www.preshweb.co.uk/cpanwww.preshweb.co.uk/github



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




Re: Dynamically created perl script

2013-03-19 Thread Brock
On 2013.03.18.22.46, Ronald Weidner wrote:
 I need to execute a Perl program that is about 1000 lines of code
 long.  The Perl program is dynamically generated by another program. I
 would like to execute the Perl program without first creating the Perl
 source code file.  In other words,' a solution that behaves like the
 source code for the Perl script was piped in instead of being opened
 from a file. This is a Linux system and the solution doesn't need to
 be portable to Windows.

It sounds like what you're doing is working, so more power to you. But
just in the way of slightly unsolicited advice, I've found over the
years that parameterizing code is better than generating code. I imagine
that an alternative approach to what you're doing might be writing a
single unchanging perl program that takes as a parameter an input file
or standard input stream of data to work on. Just something for you to
contemplate :)

--Brock


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




Re: Dynamically created perl script

2013-03-19 Thread Brandon McCaig
On Tue, Mar 19, 2013 at 12:21:10AM -0300, Brian Fraser wrote:
 You can just pipe a program into perl and it'll DWIM:
 
 $ echo 'print Hello World, Perl $^V\n' | perl

You can also be more explict about the program being on STDIN:

bash$ echo 'print Hello , World!\n' | perl -

The - tells it to read the program from STDIN. This allows you to
pass arguments to the program if necessary.

bash$ echo 'print $_\n for @ARGV' | perl - foo bar baz

From within Perl you can open a pipe to perl. For example:

#!/usr/bin/perl

use strict;
use warnings;

my $program = 'EOF';
use strict;
use warnings;

print $_\n for @ARGV;
EOF

my @args = qw(foo bar baz);

open my $fh, '|-', qw(perl -), @args or die open pipe: $!;

print $fh $program or die write to pipe: $!;

close $fh or $! == 0 or warn close pipe: $!;

__END__

See perldoc -f open and perldoc perlrun.

Of course, there's always eval() too, but that has certain
drawbacks (in particular it executes within the scope and context
of your program and can therefore tamper with it).

#!/usr/bin/perl

use strict;
use warnings;

hello();# Prints Hello, World\n!

my $program = 'EOF';
use strict;
use warnings;

hello();# Prints Hello, Satan!\n

sub hello {
print Hello, Satan!\n;
}

EOF

eval $program;

die $@ if $@;

hello();# Oops, prints Hello, Satan!\n

sub hello {
print Hello, World!\n;
}

__END__

Here is an evil example where the evaled program tampered with
the outer program in ways that may be undesirable. If you control
the inner program then you can do things to make sure that
doesn't happen accidentally (and avoid doing it intentionally).

Thanks to the warnings pragma we do get a warning about it, but
that can be surpressed, and regardless the damage may be done
already.

See perldoc -f eval and perldoc warnings.

Regards,


-- 
Brandon McCaig bamcc...@gmail.com bamcc...@castopulence.org
Castopulence Software https://www.castopulence.org/
Blog http://www.bamccaig.com/
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'



signature.asc
Description: Digital signature


Dynamically created perl script

2013-03-18 Thread Ronald Weidner
I need to execute a Perl program that is about 1000 lines of code long.  The 
Perl program is dynamically generated by another program. I would like to 
execute the Perl program without first creating the Perl source code file.  In 
other words,' a solution that behaves like the source code for the Perl script 
was piped in instead of being opened from a file. This is a Linux system and 
the solution doesn't need to be portable to Windows.

Has this been done?  Any ideas or examples?





Re: Dynamically created perl script

2013-03-18 Thread Brian Fraser
On Mon, Mar 18, 2013 at 11:46 PM, Ronald Weidner xecro...@yahoo.com wrote:
 I need to execute a Perl program that is about 1000 lines of code long.  The 
 Perl program is dynamically generated by another program. I would like to 
 execute the Perl program without first creating the Perl source code file.  
 In other words,' a solution that behaves like the source code for the Perl 
 script was piped in instead of being opened from a file. This is a Linux 
 system and the solution doesn't need to be portable to Windows.

 Has this been done?  Any ideas or examples?




You can just pipe a program into perl and it'll DWIM:

$ echo 'print Hello World, Perl $^V\n' | perl

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




Re: problem about run perl script in java

2013-02-26 Thread Luca Ferrari
I've never used, but this should be what you are looking for:
http://search.cpan.org/dist/Inline-Java/Java/PerlInterpreter/PerlInterpreter.pod

Anyway, I suspect if you cannot install a Perl version on the machine
you will not succeed in running Perl from Java.

Luca

On Tue, Feb 26, 2013 at 8:48 AM, yunbin wang accept...@gmail.com wrote:
 Now , I want run perl script in java, but I can't install perl on the
 machine, only I can copy the perl files(those installed on other
 machine) to that machine.

 so how can I initial perl INC in java that I can run perl in my java program?

 --
 Best Regards !

 --
 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: problem about run perl script in java

2013-02-26 Thread Dr.Ruud

On 2013-02-26 08:48, yunbin wang wrote:


Now , I want run perl script in java, but I can't install perl on the
machine, only I can copy the perl files(those installed on other
machine) to that machine.

so how can I initial perl INC in java that I can run perl in my java program?


Can you run JavaScript in Java? Then checkout this:
http://perlcabal.org/~fglock/perlito5.html

--
Ruud


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




problem about run perl script in java

2013-02-25 Thread yunbin wang
Now , I want run perl script in java, but I can't install perl on the
machine, only I can copy the perl files(those installed on other
machine) to that machine.

so how can I initial perl INC in java that I can run perl in my java program?

-- 
Best Regards !

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




Re: problem about run perl script in java

2013-02-25 Thread Mike Dunaway

On 2/26/13 1:48 AM, yunbin wang wrote:

Now , I want run perl script in java, but I can't install perl on the
machine, only I can copy the perl files(those installed on other
machine) to that machine.

so how can I initial perl INC in java that I can run perl in my java program?

This is a Perl programmer's mailing list. Your question is more Java 
related.


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





Re: Tutorial for a menu driven perl script

2012-12-21 Thread David Precious
On Fri, 21 Dec 2012 13:42:18 +1300
newbie01 perl newbie01.p...@gmail.com wrote:

 Hi,
 
 Does anyone know of any great source/link for tutorials on menu
 driven Perl?

Menu driven?

You may need to be more specific.

Perhaps you mean terminal-based, using e.g. curses-based stuff?

Perhaps one of the following might help:

https://metacpan.org/module/Curses::Toolkit
https://metacpan.org/module/Tickit

Or do you mean straightforward text menus (present a list of options,
let the user enter their choice)?

Or do you mean presenting a GUI?

More details needed for anyone to really help you here, I think.



-- 
David Precious (bigpresh) dav...@preshweb.co.uk
http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook
www.preshweb.co.uk/cpanwww.preshweb.co.uk/github



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




Re: Tutorial for a menu driven perl script

2012-12-21 Thread Tony Esposito
Look for tutorials on Perl/Tk
Google Perl/Tk
Here's an old one that is still good - http://www.perl.com/pub/1999/10/perltk/

HTH






 From: newbie01 perl newbie01.p...@gmail.com
To: beginners beginners@perl.org 
Sent: Thursday, 20 December 2012, 18:42
Subject: Tutorial for a menu driven perl script
 
Hi,

Does anyone know of any great source/link for tutorials on menu driven Perl?

Thanks in advance.

Tutorial for a menu driven perl script

2012-12-20 Thread newbie01 perl
Hi,

Does anyone know of any great source/link for tutorials on menu driven Perl?

Thanks in advance.


Re: Perl script on a server using Win32::OLE

2012-10-03 Thread Natxo Asenjo
On Wed, Sep 26, 2012 at 8:23 AM, Jason Feng q15...@hotmail.com wrote:

 Hello,

 I have a Perl script running on a Windows 2008 server which uses Win32::OLE 
 to dump the results on Excel files. It is working fine when I remote login to 
 the server and run the script.

 Now I want to write a Perl script on my local machine using Net::Telnet to 
 remote run the script on the server. The script on the server can be called 
 and run successfully until it attempts to open an Excel file. The error is 
 shown as the following.

 ===
 OLE exception from Microsoft Excel:

 Microsoft Excel cannot access the file
 'F:\Apps\Delta_rpt\_template.xlsx'. There are several possible
 reasons:

 • The file name or path does not exist.
 • The file is being used by another program.
 • The workbook you are trying to save has the same name as a currently open
 workbook.

 Win32::OLE(0.1709) error 0x800a03ec
 in METHOD/PROPERTYGET Open at F:\Apps\Delta_rpt\pm_delta.pl line 320
 ===

 There is no such error if I use remote desktop to the server and run the 
 script. I am wondering if Win32::OLE does not support the remote call?

is this F: drive a network mapping or a fixed disk?

If it is a network drive, then it is very likely that when calling
this code from a remote host with Net::Telnet (you are aware this is
very insecure, of course) then the mapping is not there. That would
explain the error.

-- 
groet,
natxo

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




RE: Perl script on a server using Win32::OLE

2012-10-03 Thread Jason Feng

Thanks.

F: is the local drive on the server. Now I schedule the script to be run on a 
daily base instead of calling from my local machine. So far it is OK.

Thanks anyway.

Cheers,
Jason

 Date: Wed, 3 Oct 2012 19:34:45 +0200
 Subject: Re: Perl script on a server using Win32::OLE
 From: natxo.ase...@gmail.com
 To: beginners@perl.org
 
 On Wed, Sep 26, 2012 at 8:23 AM, Jason Feng q15...@hotmail.com wrote:
 
  Hello,
 
  I have a Perl script running on a Windows 2008 server which uses Win32::OLE 
  to dump the results on Excel files. It is working fine when I remote login 
  to the server and run the script.
 
  Now I want to write a Perl script on my local machine using Net::Telnet to 
  remote run the script on the server. The script on the server can be called 
  and run successfully until it attempts to open an Excel file. The error is 
  shown as the following.
 
  ===
  OLE exception from Microsoft Excel:
 
  Microsoft Excel cannot access the file
  'F:\Apps\Delta_rpt\_template.xlsx'. There are several possible
  reasons:
 
  • The file name or path does not exist.
  • The file is being used by another program.
  • The workbook you are trying to save has the same name as a currently open
  workbook.
 
  Win32::OLE(0.1709) error 0x800a03ec
  in METHOD/PROPERTYGET Open at F:\Apps\Delta_rpt\pm_delta.pl line 320
  ===
 
  There is no such error if I use remote desktop to the server and run the 
  script. I am wondering if Win32::OLE does not support the remote call?
 
 is this F: drive a network mapping or a fixed disk?
 
 If it is a network drive, then it is very likely that when calling
 this code from a remote host with Net::Telnet (you are aware this is
 very insecure, of course) then the mapping is not there. That would
 explain the error.
 
 -- 
 groet,
 natxo
 
 -- 
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/
 
 
  

Perl script on a server using Win32::OLE

2012-09-26 Thread Jason Feng

Hello,

I have a Perl script running on a Windows 2008 server which uses Win32::OLE to 
dump the results on Excel files. It is working fine when I remote login to the 
server and run the script.

Now I want to write a Perl script on my local machine using Net::Telnet to 
remote run the script on the server. The script on the server can be called and 
run successfully until it attempts to open an Excel file. The error is shown as 
the following.

===
OLE exception from Microsoft Excel:

Microsoft Excel cannot access the file
'F:\Apps\Delta_rpt\_template.xlsx'. There are several possible
reasons:

• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open
workbook.

Win32::OLE(0.1709) error 0x800a03ec
in METHOD/PROPERTYGET Open at F:\Apps\Delta_rpt\pm_delta.pl line 320
===

There is no such error if I use remote desktop to the server and run the 
script. I am wondering if Win32::OLE does not support the remote call?

Any help is really appreciated!

Thanks in advance.

Best regards,
Jason
  

Re: Clarification re Perl Script out of control

2012-09-14 Thread David Precious
On Thu, 13 Sep 2012 22:56:18 -0700 (PDT)
jmrhide-p...@yahoo.com wrote:
 Where I think we need to focus is, assuming the script runs to its
 end every time, why doesn't it release its hold on the server
 resources? My hosting service runs Apache version 2.2.22. I can't
 tell what version of Perl they run. I had been relying on the idea
 that a mannerly Perl interpreter would automatically release
 resources when it runs out of statements to execute. Is it possible
 that I need to include some sort of END declaration? 

No - the interpreter will exit when it's done executing the script.

If it isn't exiting, that would suggest it's still executing it -
likely stuck within one of those while (1) loops.

If your host wanted to be particularly helpful, when they see a process
stuck using up CPU time, they could attach with strace and see what
syscalls it's making at the time, as that *might* give some kind of
clue.

Alternatively, you could sprinkle debugging log messages throughout,
hoping that will let you see by looking at the logs what's going on.

Or, you could see if you can install and use Runops::Recorder which can
trace and record the execution flow of your program.


-- 
David Precious (bigpresh) dav...@preshweb.co.uk
http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook
www.preshweb.co.uk/cpanwww.preshweb.co.uk/github



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




Re: Clarification re Perl Script out of control

2012-09-14 Thread Paul Anderson

On 2012-09-14, at 1:56 AM, jmrhide-p...@yahoo.com wrote:

 I can see from the responses so far that I was unclear in the way I phrased 
 my 
 question, so please let me emphasize the following: MY SCRIPT, THOUGH COMPLEX 
 (500 LINES), PRODUCES EXACTLY THE OUTPUT I EXPECT EVERY TIME I RUN IT. In 
 particular, it never hangs or gives a wrong answer. Also, with all error 
 trapping enabled, no error appears on the server log. 
 

You were quite clear. The problem is that the script as it stands is very 
complex, and not well organized. This makes debugging much more difficult. The 
design of the script also makes it exceedingly difficult to make any changes to 
things like the style of the pages it generates. It adds a great deal of 
headaches. Rewriting, while indeed time consuming, quite probably will not take 
terribly long, resolve the current bug, and result in a script that is much 
more easily maintained and debugged. It's an investment in the future of the 
script, making your own life easier.

 
 Where I think we need to focus is, assuming the script runs to its end every 
 time, why doesn't it release its hold on the server resources?

Ahh, there's the rub! You assume it ends every time! This assumption is not 
necessarily valid. Just because it behaves itself for you doesn't necessarily 
mean there isn't something weird that you aren't reproducing. It could even be 
a bug that is very unlikely. If it only happens once in a thousand times of 
being run, a busy site can make it go off many times per day, whereas debugging 
at home will never make it go off. The while(1) loops themselves are perilous. 
If the logic doesn't behave in the way you hope, and something weird happens, 
you have an infinite loop. That would cause the exact problem you describe. It 
would also not produce any errors - because no real error has occurred. The 
program has just assumed an internal state you didn't anticipate. I think at 
the top of your list is reworking those loops so that they are no longer 
infinite.

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




Clarification re Perl Script out of control

2012-09-13 Thread jmrhide-perl
I can see from the responses so far that I was unclear in the way I phrased my 
question, so please let me emphasize the following: MY SCRIPT, THOUGH COMPLEX 
(500 LINES), PRODUCES EXACTLY THE OUTPUT I EXPECT EVERY TIME I RUN IT. In 
particular, it never hangs or gives a wrong answer. Also, with all error 
trapping enabled, no error appears on the server log. 


Where I think we need to focus is, assuming the script runs to its end every 
time, why doesn't it release its hold on the server resources? My hosting 
service runs Apache version 2.2.22. I can't tell what version of Perl they run. 
I had been relying on the idea that a mannerly Perl interpreter would 
automatically release resources when it runs out of statements to execute. Is 
it 
possible that I need to include some sort of END declaration? 


 John M Rathbun MD


Can not run ssh command inside perl script !

2012-08-31 Thread Jack Vo

Hello List,

I'm trying to execute a script which retrieves swap usage memory in 
remote host. So that I install Net::SSH::Perl module (from source code) 
from CPAN website.

My script below :

#!/usr/bin/perl -w
use strict;
use Net::SSH::Perl;

my $hostname = 192.168.7.5;
my $username = abcd;
my $password = abcd;

my $cmd = free -m;

my $ssh = Net::SSH::Perl-new($hostname, debug=0);
$ssh-login($username,$password);
my ($stdout,$stderr,$exit) = $ssh-cmd($cmd);
But the output has some error message and don't know how to solve this 
problem.
Can't locate Math/Pari.pm in @INC (@INC contains: 
/usr/lib/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 
/usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi 
/usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl 
/usr/lib/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi 
/usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl .) at 
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Util/SSH2MP.pm line 6, 
GEN0 line 1.
BEGIN failed--compilation aborted at 
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Util/SSH2MP.pm line 6, 
GEN0 line 1.
Compilation failed in require at 
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Util.pm line 56, GEN0 
line 1.
BEGIN failed--compilation aborted at 
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Kex/DH1.pm line 10, GEN0 
line 1.
Compilation failed in require at 
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Kex.pm line 6, GEN0 line 1.
BEGIN failed--compilation aborted at 
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Kex.pm line 6, GEN0 line 1.
Compilation failed in require at 
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/SSH2.pm line 6, GEN0 line 1.
BEGIN failed--compilation aborted at 
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/SSH2.pm line 6, GEN0 line 1.
Compilation failed in require at 
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl.pm line 52, GEN0 line 1.
Did I miss install Math module ? This is modules which already installed 
in server.

perl-32bit-5.8.8-14.10
perl-Parse-RecDescent-1.80-259.2
perl-Crypt-SmbHash-0.12-13.2
perl-DBD-SQLite-1.11-14.6
perl-Config-IniFiles-2.39-13.4
perl-URI-1.35-15.2
perl-X500-DN-0.28-133.2
perl-Date-Calc-5.4-14.5
perl-Config-Crontab-1.11-12.2
perl-File-Tail-0.99.3-12.2
perl-TimeDate-1.16-136.2
perl-gettext-1.05-13.2
perl-DBI-1.50-13.2
perl-Compress-Zlib-1.35-14.2
perl-Digest-SHA1-2.10-15.2
perl-TermReadKey-2.30-13.2
perl-XML-Writer-0.600-13.2
perl-PlRPC-0.2018-13.2
perl-Bootloader-0.4.19.21-0.4.12
perl-Carp-Clan-5.3-13.5
perl-Digest-MD4-1.5-13.2
perl-XML-Parser-2.34-43.2
perl-Net-Daemon-0.38-61.2
perl-libapparmor-2.2-0.3
perl-Bit-Vector-6.4-13.5

- Some Information :
OS : SUSE Linux SP3.
Perl version : perl-5.8.8-14.10

Any help is greatly appriciated.

--
Thank and best regards,
Jack Vo



Re: Can not run ssh command inside perl script !

2012-08-31 Thread Shlomi Fish
Hello Jack,

On Fri, 31 Aug 2012 17:00:12 +0700
Jack Vo jacksvo2...@gmail.com wrote:

 Hello List,
 
 I'm trying to execute a script which retrieves swap usage memory in 
 remote host. So that I install Net::SSH::Perl module (from source
 code) from CPAN website.
 My script below :
  #!/usr/bin/perl -w
  use strict;
  use Net::SSH::Perl;
 
  my $hostname = 192.168.7.5;
  my $username = abcd;
  my $password = abcd;
 
  my $cmd = free -m;
 
  my $ssh = Net::SSH::Perl-new($hostname, debug=0);
  $ssh-login($username,$password);
  my ($stdout,$stderr,$exit) = $ssh-cmd($cmd);
 But the output has some error message and don't know how to solve
 this problem.
  Can't locate Math/Pari.pm in @INC (@INC contains: 
  /usr/lib/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 
  /usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi 
  /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl 
  /usr/lib/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi 
  /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl .) at 
  /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Util/SSH2MP.pm line 6, 
  GEN0 line 1.

This means you need to install the Math::Pari module from CPAN or from your
distribution's package repository. On rpm-based systems installing 
perl-Math-Pari
should work.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Parody of The Fountainhead - http://shlom.in/towtf

Confucius says: “XSLT made me realise humanity was hopeless.”.

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/




Slightly OT: POST data to perl script

2012-07-24 Thread Mark Haney
This is slightly OT, but I'm kinda under a dead line and am hoping 
someone takes pity on me and supplies an answer.  I have a small 
webserver that takes data from a custom chip and sends it via a POST to 
a perl script on our primary webserver.  The data is sent like 
TIME=XXTOWER= where the Y's are single digit integers denoting 
the status of a light on the machine.  (0,1,2 for each integer)


The problem I'm seeing in tcpdump is that it appears that the first two 
integers are being dropped if they are both zeroes.  It doesn't seem to 
happen with a first digit being !=0.  I can't say (but suspect) if the 
first digit only = 0 if it gets dropped, since the data won't come with 
that output.


I know this is an HTML type issue, but is there something I'm missing? 
Maybe an escape char that would keep that from happening?


--

Mark Haney
Software Developer/Consultant
AB Emblem
ma...@abemblem.com
Linux marius.homelinux 3.4.4-4.fc16.x86_64 GNU/Linux


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




Re: Slightly OT: POST data to perl script

2012-07-24 Thread Shawn H Corey
On Tue, 24 Jul 2012 11:53:33 -0400
Mark Haney ma...@abemblem.com wrote:

 The problem I'm seeing in tcpdump is that it appears that the first
 two integers are being dropped if they are both zeroes.

You could reconstruct the leading zeros in your Perl script.

for my $n ( 0 .. 10 ){
  my $m = sprintf( '%04d', $n );
  print $n  ==  $m\n;
}


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

_Perl links_
official site   : http://www.perl.org/
beginners' help : http://learn.perl.org/faq/beginners.html
advance help: http://perlmonks.org/
documentation   : http://perldoc.perl.org/
news: http://perlsphere.net/
repository  : http://www.cpan.org/
blog: http://blogs.perl.org/
regional groups : http://www.pm.org/

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




Re: Slightly OT: POST data to perl script

2012-07-24 Thread Mark Haney

On 07/24/2012 12:20 PM, Shawn H Corey wrote:

On Tue, 24 Jul 2012 11:53:33 -0400
Mark Haney ma...@abemblem.com wrote:


The problem I'm seeing in tcpdump is that it appears that the first
two integers are being dropped if they are both zeroes.


You could reconstruct the leading zeros in your Perl script.

for my $n ( 0 .. 10 ){
   my $m = sprintf( '%04d', $n );
   print $n  ==  $m\n;
}




Yeah, it certainly looks like I'll have to for now anyway.  I don't 
really have time to tinker with the other end until after the meeting 
with the bosses tomorrow.


Thanks for the suggestions.


--

Mark Haney
Software Developer/Consultant
AB Emblem
ma...@abemblem.com
Linux marius.homelinux 3.4.4-4.fc16.x86_64 GNU/Linux



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




Perl script logging permissions

2012-05-26 Thread Kwaku Addo Ofori
Hi Guys,

I need some help. I've just finished my script and a manual test is fine.
Basically, it's a script that gets the PID of some selected process and
lists all the open file descriptors for the processes pipes this to a file.
Problem is, when I run the script manually it works well and writes the
file descriptor info to the log file but when I put this same script in
cron it can't log to the file.

I know this is a permissions problem and I've played around with the
permissions but it still can't log to the file when the script is run from
cron. Any idea on how to debug this?

Kwaku.


Re: Perl script logging permissions

2012-05-26 Thread David Christensen

On 05/26/2012 12:33 PM, Kwaku Addo Ofori wrote:

I need some help. I've just finished my script and a manual test is fine.
Basically, it's a script that gets the PID of some selected process and
lists all the open file descriptors for the processes pipes this to a file.
Problem is, when I run the script manually it works well and writes the
file descriptor info to the log file but when I put this same script in
cron it can't log to the file.
I know this is a permissions problem and I've played around with the
permissions but it still can't log to the file when the script is run from
cron. Any idea on how to debug this?


Ideas:

1.  Create a world-writable directory and have your script put its log 
file there.  This is okay for development/ test, but is not secure.


2.  Figure out what user/group cron runs your script under (write a test 
script using #1, above), create a directory owned by that user/ group, 
and have your script write its log there.


3. man cron(8) on my system (Debian 6) says that cron will mail the 
output of the job to a configurable user.  So, instead of writing to a 
log file, have your script write to STDOUT and make sure cron can send 
e-mails.


4.  Set the setuid bit on the script (not secure; might not work under 
cron).



Please let us know what you figure out.


HTH,

David

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




how to display commands while perl script executing

2012-05-15 Thread Sunita.Pradhan
Hi

I want to print the command during script execution .
Example :


===
$ls = `ls`;

Print $ls\n;
==

In the above script I want to print ls command before 'ls' command gets 
executed . Like  set -x does  in  shell scripts .

Could you please help me on this ?

Thanks
Sunita




Re: how to display commands while perl script executing

2012-05-15 Thread CloudWebDNS.com

Hello,

Try this:

$ perl -le '$c=ls -l;print $c;system $c'
ls -l
total 16
drwxr-xr-x 4 pyh pyh 4096 2012-05-12 17:08 backup
drwxr-xr-x 2 pyh pyh 4096 2012-05-13 08:29 bin
drwxr-xr-x 5 pyh pyh 4096 2012-05-03 11:03 ipdata
drwxr-xr-x 4 pyh pyh 4096 2012-05-14 10:34 tmp




Hi

 I want to print the command during script execution .
Example :


===
$ls = `ls`;

Print $ls\n;
==

In the above script I want to print ls command before 'ls' command gets executed . Like 
 set -x does  in  shell scripts .

Could you please help me on this ?

Thanks
Sunita







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




RE: how to display commands while perl script executing

2012-05-15 Thread Sunita.Pradhan
It is working for one line program . How can we implement in a script ?

-Sunita

-Original Message-
From: CloudWebDNS.com [mailto:supp...@cloudwebdns.com] 
Sent: Tuesday, May 15, 2012 5:27 PM
To: beginners@perl.org
Subject: Re: how to display commands while perl script executing

Hello,

Try this:

$ perl -le '$c=ls -l;print $c;system $c'
ls -l
total 16
drwxr-xr-x 4 pyh pyh 4096 2012-05-12 17:08 backup
drwxr-xr-x 2 pyh pyh 4096 2012-05-13 08:29 bin
drwxr-xr-x 5 pyh pyh 4096 2012-05-03 11:03 ipdata
drwxr-xr-x 4 pyh pyh 4096 2012-05-14 10:34 tmp



 Hi

  I want to print the command during script execution .
 Example :


 ===
 $ls = `ls`;

 Print $ls\n;
 ==

 In the above script I want to print ls command before 'ls' command gets 
 executed . Like  set -x does  in  shell scripts .

 Could you please help me on this ?

 Thanks
 Sunita






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





Re: how to display commands while perl script executing

2012-05-15 Thread Shlomi Fish
Hi Sunita,
 
On Tue, 15 May 2012 07:40:44 -0400
sunita.prad...@emc.com wrote:

 Hi
 
 I want to print the command during script execution .
 Example :
 
 
 ===
 $ls = `ls`;
 
 Print $ls\n;
 ==
 

I should note that trapping the output of ls is pretty silly because there
are built-in routines and CPAN modules for doing that which are more portable
and less error-prone than piping to the shell for input. 

You also want print in all lower-case instead of Print with an uppercase
P.

 In the above script I want to print ls command before 'ls' command gets 
 executed . Like  set -x does  in  shell scripts .
 
 Could you please help me on this ?
 

You can do it for each and every Perl statement using
https://metacpan.org/module/Devel::TraceVars or maybe using 
https://metacpan.org/module/Devel::Trace .
If you want to do it only for shell commands executed using backticks, then you
can search for qx in http://perldoc.perl.org/overload.html (and you can also
try setting a shell environment variable to add -x to all shell-executed
commands).

Regards,

Shlomi Fish 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Chuck Norris/etc. Facts - http://www.shlomifish.org/humour/bits/facts/

You name it — COBOL does not have it.

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: how to display commands while perl script executing

2012-05-15 Thread Michael Rasmussen
On Tue, May 15, 2012 at 07:40:44AM -0400, sunita.prad...@emc.com wrote:
 Hi
 
 I want to print the command during script execution .
 Example :
 
 ===
 $ls = `ls`;
 
 Print $ls\n;
 ==

A straightforward way to do this is to run your script with the perl debugger:

 perl -d script_name

When it loads you'll see something like:

michael@bivy:~$ perl -d tpl

Loading DB routines from perl5db.pl version 1.32
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(tpl:5):  my %index;   The first executable line of your 
script

Then press n on your keyboard to run the next command:

  DB1 n   
 
main::(tpl:6):  my @file = DATA;

And after that just press ENTER to execute each command in turn. 

As you might imagine you can do other things with the debugger too.

-- 
Michael Rasmussen, Portland Oregon  
  Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
Happiness is a path, not a destination.
~ Tay Gillespie by way of Mark Canizaro

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




RE: how to display commands while perl script executing

2012-05-15 Thread Bob McConnell
 From: Sunita.Pradhan
 
 I want to print the command during script execution .
 Example :
 
 
 ===
 $ls = `ls`;
 
 Print $ls\n;
 ==
 
 In the above script I want to print ls command before 'ls' command gets
 executed . Like  set -x does  in  shell scripts .
 
 Could you please help me on this ?

Are you looking for a Perl script, or just a shell script? Using Perl for this 
appears to be like using a baseball bat to swat a fly. But here in a Perl 
mailing list, you are going to get Perl scripts. If that is not what you are 
looking for, you need to find a mailing list for your particular shell, which 
you didn't name.

Bob McConnell


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




Re: how to display commands while perl script executing

2012-05-15 Thread Torqued


Regards.../om

On 15-May-2012, at 18:23, Bob McConnell r...@cbord.com wrote:

 From: Sunita.Pradhan
 
I want to print the command during script execution .
 Example :
 
 
 ===
 $ls = `ls`;
 
 Print $ls\n;
 ==
 
 In the above script I want to print ls command before 'ls' command gets
 executed . Like  set -x does  in  shell scripts .
 
 Could you please help me on this ?
 
It looks to me she is simply looking for a debugger, set -x in shell helps in 
debugging the scripts, for perl the best option would be to use 'perl -d script 
name' option.

 Are you looking for a Perl script, or just a shell script? Using Perl for 
 this appears to be like using a baseball bat to swat a fly. But here in a 
 Perl mailing list, you are going to get Perl scripts. If that is not what you 
 are looking for, you need to find a mailing list for your particular shell, 
 which you didn't name.
 
 Bob McConnell
 
 
 -- 
 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/




Perl script not executing from cron job

2012-03-27 Thread Anirban Adhikary
Hi
I need to run a perl script from cron tab.

so I write a small shell script and call the perl script within that shell
script.
/usr/bin/perl /home/anirban/perl_code.pl

Before calling the perl script I copied all the contents of the .profile
file and paste it within the shell script.

But still the code is not running.

Best Regards
Anirban Adhikary.


Re: Perl script not executing from cron job

2012-03-27 Thread Paul Johnson
On Tue, Mar 27, 2012 at 04:30:27PM +0530, Anirban Adhikary wrote:
 Hi
 I need to run a perl script from cron tab.
 
 so I write a small shell script and call the perl script within that shell
 script.
 /usr/bin/perl /home/anirban/perl_code.pl
 
 Before calling the perl script I copied all the contents of the .profile
 file and paste it within the shell script.
 
 But still the code is not running.

cron problems are almost invariably due to environment or permissions
problems.  You seem to have addressed the environment part, so my guess
would be permissions.

The rest of the time the problem is to do with unescaped % characters.

All this assuming the script works correctly outside of cron.

Have you looked at the cron logs?

The easiest way to debug further is probably to redirect stderr and
stdout to a file in your crontab entry and narrow down the problems that
way.  This involves chaning the time the cronjob runs every time you
need to run a test, which is a real pain and seems like the sort of
thing for which there really should be a better solution.  With luck,
someone will reply and say what that solution is.

Good luck,

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

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




Re: Perl script not executing from cron job

2012-03-27 Thread Anirban Adhikary
Hi All,
I have found the solution.
I need to write a line to top of my code and its works.
use Lib Path to your perl code;
then I can run this perl code directly from crontab I dont need a shell
script to call the perl code.

Thanks
Anirban Adhikary.

On Tue, Mar 27, 2012 at 7:41 PM, Paul Johnson p...@pjcj.net wrote:

 On Tue, Mar 27, 2012 at 04:30:27PM +0530, Anirban Adhikary wrote:
  Hi
  I need to run a perl script from cron tab.
 
  so I write a small shell script and call the perl script within that
 shell
  script.
  /usr/bin/perl /home/anirban/perl_code.pl
 
  Before calling the perl script I copied all the contents of the .profile
  file and paste it within the shell script.
 
  But still the code is not running.

 cron problems are almost invariably due to environment or permissions
 problems.  You seem to have addressed the environment part, so my guess
 would be permissions.

 The rest of the time the problem is to do with unescaped % characters.

 All this assuming the script works correctly outside of cron.

 Have you looked at the cron logs?

 The easiest way to debug further is probably to redirect stderr and
 stdout to a file in your crontab entry and narrow down the problems that
 way.  This involves chaning the time the cronjob runs every time you
 need to run a test, which is a real pain and seems like the sort of
 thing for which there really should be a better solution.  With luck,
 someone will reply and say what that solution is.

 Good luck,

 --
 Paul Johnson - p...@pjcj.net
 http://www.pjcj.net



Re: Perl script not executing from cron job

2012-03-27 Thread Shawn H Corey

On 12-03-27 10:16 AM, Anirban Adhikary wrote:

I have found the solution.
I need to write a line to top of my code and its works.
use Lib Path to your perl code;
then I can run this perl code directly from crontab I dont need a shell
script to call the perl code.


Try using FindBin. FindBin was written to solve problems like this and 
it doesn't require a hard-coded path; you can move your script around 
and it still works.



use FindBin qw( $RealBin );
use lib $RealBin;

# application's `use module;` go here


--
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

[edited for today's programmers]
Show me your code and conceal your interfaces, and I shall continue
to be mystified. Show me your interfaces, and I won't usually need
your code; it'll be obvious.
-- Fred Brooks

If you want to make something that's dirt cheap, make it out of dirt.
-- Donald Sadoway

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




Re: Perl Module to parse any other Perl script/module to fetch stats about data-structures

2012-02-13 Thread Randal L. Schwartz
 Parag == Parag Kalra paragka...@gmail.com writes:

Parag Do we have any Perl module which can parse any other perl script
Parag (or module) and fetch information like total number of arrays
Parag being used, total number of hashes, total number of scalar
Parag variables etc and size information (like total elements, total
Parag keys etc) for each data structure in that perl script or may be
Parag another perl module

It's not possible to completely parse Perl statically [1], although PPI
[2] is pretty close and usable for most programs.

[1] http://www.perlmonks.org/index.pl?node_id=44722
[2] http://search.cpan.org/~adamk/PPI-1.215/lib/PPI.pm

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion

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




Re: Perl Module to parse any other Perl script/module to fetch stats about data-structures

2012-02-09 Thread Shawn H Corey

On 12-02-08 05:20 PM, Parag Kalra wrote:

Do we have any Perl module which can parse any other perl script (or
module) and fetch information like total number of arrays being used, total
number of hashes, total number of scalar variables etc and size information
  (like total elements, total keys etc) for each data structure in that perl
script or may be another perl module

Thanks,
Parag



I haven't found a module to do exactly what you want, but B::Xref may do 
for a start:


perl -MO=Xref myscript

See `perldoc B::Xref` for details.


--
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

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




Perl Module to parse any other Perl script/module to fetch stats about data-structures

2012-02-08 Thread Parag Kalra
Do we have any Perl module which can parse any other perl script (or
module) and fetch information like total number of arrays being used, total
number of hashes, total number of scalar variables etc and size information
 (like total elements, total keys etc) for each data structure in that perl
script or may be another perl module

Thanks,
Parag


Re: Perl Module to parse any other Perl script/module to fetch stats about data-structures

2012-02-08 Thread Steve Bertrand

On 2012.02.08 17:20, Parag Kalra wrote:

Do we have any Perl module which can parse any other perl script (or
module) and fetch information like total number of arrays being used, total
number of hashes, total number of scalar variables etc and size information
  (like total elements, total keys etc) for each data structure in that perl
script or may be another perl module


I've written such to identify subs within my own apps for which I've 
written numerous interconnected modules, but never had the need to see 
individual elements. Even my own internal traces didn't follow single 
elements.


I would suspect that this would be something that would have to run 
against the file itself, even prior to compile.


Curious task. Might I ask what the purpose of your desire is?

Steve

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




Re: Perl Module to parse any other Perl script/module to fetch stats about data-structures

2012-02-08 Thread Jeff Peng

于 2012-2-9 10:15, Steve Bertrand 写道:


I would suspect that this would be something that would have to run 
against the file itself, even prior to compile.


Curious task. Might I ask what the purpose of your desire is? 


I am also not sure what's the special purpuse of the OP.
Some modules on CPAN under the namespace of Devel::* may help him.

Jeff.

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




Re: Perl Module to parse any other Perl script/module to fetch stats about data-structures

2012-02-08 Thread Parag Kalra
By data-structures being used, I mean the data structures that are actually
*declared* in the script.

And is it possible to find at least the data-structures stats of the
current script that is getting executed if no parser is available.

For example if I have a big script or module and if I want to find total
arrays, hashes and variables declared in that script. Is there any special
variable where this info is stored.

Thanks,
Parag

On Wed, Feb 8, 2012 at 6:31 PM, Jeff Peng p...@staff.dnsbed.com wrote:

 于 2012-2-9 10:15, Steve Bertrand 写道:


 I would suspect that this would be something that would have to run
 against the file itself, even prior to compile.

 Curious task. Might I ask what the purpose of your desire is?


 I am also not sure what's the special purpuse of the OP.
 Some modules on CPAN under the namespace of Devel::* may help him.

 Jeff.

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





Re: Perl Module to parse any other Perl script/module to fetch stats about data-structures

2012-02-08 Thread Jeff Peng

于 2012-2-9 15:21, Parag Kalra 写道:
By data-structures being used, I mean the data structures that are 
actually *declared* in the script.


And is it possible to find at least the data-structures stats of the 
current script that is getting executed if no parser is available.


For example if I have a big script or module and if I want to find 
total arrays, hashes and variables declared in that script. Is there 
any special variable where this info is stored.


I'm not sure, but you may take a look at this module:
http://search.cpan.org/~flora/perl-5.14.2/ext/Devel-Peek/Peek.pm 
http://search.cpan.org/%7Eflora/perl-5.14.2/ext/Devel-Peek/Peek.pm


HTH.


Replace words in a file using perl script

2011-12-16 Thread Melvin
Hi,

I am a Perl baby :-)

I was trying to write a script to replace baby to bigboy in a file:-
However the below script doesn't work Could someone help me???

#!/usr/bin/perl -w
use strict;

open (FILE_IN , $ARGV[0]) || die (ERROR: Gimme Input pleease);

my @array_of_lines = FILE_IN;

foreach my $line (@array_of_lines)

{
$line =~ s/baby/bigboy/g;

}

close FILE_IN;


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




Re: Replace words in a file using perl script

2011-12-16 Thread Jim Gibson
On 12/15/11 Thu  Dec 15, 2011  7:36 AM, Melvin whereismel...@gmail.com
scribbled:

 Hi,
 
 I am a Perl baby :-)
 
 I was trying to write a script to replace baby to bigboy in a file:-
 However the below script doesn't work Could someone help me???

The problem with your script is that you are not writing out the modified
strings to the file. Thus, the changes are lost when the program terminates.
Check 'perldoc -f open' for how to open a file for writing.

A more efficient program will open the original file for reading, open a new
file for writing (with a different name), read each line in the input file,
apply the change, then write the modified line to the output file. You can
use the following statements

while( my $line = FILE_IN ) { ...

to read a line from the input file

$line =~ s/baby/bigboy/g

to modify the line and

print $file_out $line;

to write the file.

Note that it is generally better to use lexical variables ($file_out) rather
than globals (FILE_IN) for file handles.

It is also better to use the three-argument version of open.

Once you have the new file written successfully, you can rename it to the
old file name, either manually or within your program (using the rename
function). If you do the latter, first rename the old file so that you have
a backup, just in case.

 
 #!/usr/bin/perl -w
 use strict;
 
 open (FILE_IN , $ARGV[0]) || die (ERROR: Gimme Input pleease);
 
 my @array_of_lines = FILE_IN;
 
 foreach my $line (@array_of_lines)
 
 {
 $line =~ s/baby/bigboy/g;
 
 }
 
 close FILE_IN;
 



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




RE: Replace words in a file using perl script

2011-12-16 Thread Kronheim, David (Contr)
Hi Melvin,

It looks like you're editing each line but not writing back to the file,
add some print's or say's for $line to see what's happening.

Sincerely,
David Kronheim
Production Support Tier II
Gateway Error Correction, VZ450 EDI, EDI Billing,  Metakey/LIA
484-213-1315

From: Melvin [whereismel...@gmail.com]
Sent: Thursday, December 15, 2011 10:36 AM
To: beginners@perl.org
Subject: Replace words in a file using perl script

Hi,

I am a Perl baby :-)

I was trying to write a script to replace baby to bigboy in a file:-
However the below script doesn't work Could someone help me???

#!/usr/bin/perl -w
use strict;

open (FILE_IN , $ARGV[0]) || die (ERROR: Gimme Input pleease);

my @array_of_lines = FILE_IN;

foreach my $line (@array_of_lines)

{
$line =~ s/baby/bigboy/g;

}

close FILE_IN;


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

This communication is confidential.  Frontier only sends and receives email on 
the basis of the terms set out at http://www.frontier.com/email_disclaimer.

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




Re: Replace words in a file using perl script

2011-12-16 Thread Chris Stinemetz
Hello Melvin,

Give this a try. I used the advice Jim gave and this is what I came up
with. It seems to do what you are asking for.

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

my $inFile = input.txt;
my $outFile = output.txt;

open my $fin, '', $inFile or die ERROR opening $inFile: $!;
open my $out, '', $outFile or die ERROR opening $outFile: $!;

while( my $line = $fin ) {
  $line =~ s/baby/bigboy/g;
  print $out $line;
}

HTH,

Chris

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




Re: Replace words in a file using perl script

2011-12-16 Thread Uri Guttman

On 12/16/2011 03:23 PM, Chris Stinemetz wrote:

Hello Melvin,

Give this a try. I used the advice Jim gave and this is what I came up
with. It seems to do what you are asking for.

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

my $inFile = input.txt;
my $outFile = output.txt;

open my $fin, '', $inFile or die ERROR opening $inFile: $!;
open my $out, '', $outFile or die ERROR opening $outFile: $!;

while( my $line =$fin  ) {
   $line =~ s/baby/bigboy/g;
   print $out $line;
}


or even simpler and much faster:

use File::Slurp qw( edit_file ) ;

edit_file { s/baby/bigboy/g } 'file.txt' ;

it will edit the file in place safely.

uri


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




Re: Replace words in a file using perl script

2011-12-16 Thread Brandon McCaig
On Thu, Dec 15, 2011 at 07:36:37AM -0800, Melvin wrote:
 Hi,

Hello:

 I was trying to write a script to replace baby to bigboy in a file:-
 However the below script doesn't work Could someone help me???
 
 #!/usr/bin/perl -w
 use strict;
 
 open (FILE_IN , $ARGV[0]) || die (ERROR: Gimme Input pleease);
 
 my @array_of_lines = FILE_IN;
 
 foreach my $line (@array_of_lines)
 
 {
 $line =~ s/baby/bigboy/g;
 
 }
 
 close FILE_IN;

You are attempting to modify the file in place, but that isn't
how it works. :) You can apparently use the File::Slurp module to
do that though. IIRC from Uri's examples there's an edit_file
function. (*Checks documentation*) Oooh, neat:

#!/usr/bin/perl

use File::Slurp;

die 'invalid arguments' unless @ARGV;

edit_file { s/baby/bigboy/g } $ARGV[0];

__END__

Untested. :)

Regards,


-- 
Brandon McCaig bamcc...@gmail.com bamcc...@castopulence.org
Castopulence Software https://www.castopulence.org/
Blog http://www.bamccaig.com/
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'



signature.asc
Description: Digital signature


Re: perl script help

2011-10-13 Thread james varghese
Thanks for the Suggestions Ken Slater and Jin Gibson.

Sorry for the missing information's.

Exactly what you people predicted is correct.($k is a file counter
starting at zero, and $Line_Counter is a line counter starting at one)

Script is modified according to the suggestions given by you and now
its working fine.

Thanks again,
James



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




perl script help

2011-10-11 Thread james varghese
hi,
I am new to perl programming.I am trying with the following script and
need help for it.

I consolidated 10 excel files(in .txt format) which has same headers
in it and so i made it 1 common header at the top.While doing it,in
final output file i see a blank row at the beginning of every file
consolidated.I wanted to get rid of it and to be displayed all in a
single file.

Sample Script:

while(FILE) {
if (($k ==0) and ($Line_Counter ==1)) {
my @F=split(/[\t]+/, $_);
print CONSOL_FILE $F[0] \t $F[1] \t $F[2] \n;
}
if (($k =1) and ($Line_Counter1)) {   # doesnt print 
headers
$Line=$_;
my @F=split(/[\t]+/, $Line);
print CONSOL_FILE  $F[0] \t $F[1] \t $F[2] \n;
}
$Line_Counter = $Line_Counter + 1;
}
close FILE ;
note:tab is the delimiter used here.

Any help is Appreciated.


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




RE: perl script help

2011-10-11 Thread Ken Slater
 From: james varghese [mailto:james2...@gmail.com]
 Sent: Tuesday, October 11, 2011 8:31 AM
 To: beginners@perl.org
 Subject: perl script help
 
 hi,
 I am new to perl programming.I am trying with the following script and
 need help for it.
 
 I consolidated 10 excel files(in .txt format) which has same headers
 in it and so i made it 1 common header at the top.While doing it,in
 final output file i see a blank row at the beginning of every file
 consolidated.I wanted to get rid of it and to be displayed all in a
 single file.
 
 Sample Script:
 
 while(FILE) {
   if (($k ==0) and ($Line_Counter ==1)) {
   my @F=split(/[\t]+/, $_);
   print CONSOL_FILE $F[0] \t $F[1] \t $F[2]
\n;
   }
   if (($k =1) and ($Line_Counter1)) {   # doesnt
 print headers
   $Line=$_;
   my @F=split(/[\t]+/, $Line);
   print CONSOL_FILE  $F[0] \t $F[1] \t $F[2]
 \n;
   }
 $Line_Counter = $Line_Counter + 1;
   }
   close FILE ;
 note:tab is the delimiter used here.
 
 Any help is Appreciated.
 

Hi,
Not certain if this is your problem, but you probably want to 'chomp' the
input after reading a line.
Also, what is $k?
You may be able to read the first line outside the loop and print the
header. Then you would not have to worry about the checks for $line_number
(and $k?).
And why do you assign $Line to $_? Seems like an unnecessary step.
As an aside, when referring to the Perl programming language it is usually
capitalized (Perl).
Ken





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




Re: perl script help

2011-10-11 Thread Jim Gibson
On 10/11/11 Tue  Oct 11, 2011  5:31 AM, james varghese
james2...@gmail.com scribbled:

 hi,
 I am new to perl programming.I am trying with the following script and
 need help for it.
 
 I consolidated 10 excel files(in .txt format) which has same headers
 in it and so i made it 1 common header at the top.While doing it,in
 final output file i see a blank row at the beginning of every file
 consolidated.I wanted to get rid of it and to be displayed all in a
 single file.

Are you saying that there is a blank line in the consolidated file just
before the first line of each copied file? I will assume so, but please
correct me if I am wrong.

 
 Sample Script:
 
 while(FILE) {
 if (($k ==0) and ($Line_Counter ==1)) {
 my @F=split(/[\t]+/, $_);
 print CONSOL_FILE $F[0] \t $F[1] \t $F[2] \n;
 }
 if (($k =1) and ($Line_Counter1)) {   # doesnt print headers
$Line=$_;
 my @F=split(/[\t]+/, $Line);
 print CONSOL_FILE  $F[0] \t $F[1] \t $F[2] \n;
 }
 $Line_Counter = $Line_Counter + 1;
 }
 close FILE ;
 note:tab is the delimiter used here.
 
 Any help is Appreciated.
 

You have not shown us the whole program, so it is difficult to help you. I
see nothing wrong with the logic of your program, so the problem may lie
with what you have not shown us.

Specifically, what is $k, what is its initial value, and when does the value
change? It looks like a file counter. Also, what is the initial value of
$Line_Counter, and does it get re-initialized for each file read?

Assuming $k is a file counter starting at zero, and $Line_Counter is a line
counter starting at one, you can use the following logic to skip printing
the first line of each file read except for the first:

   if( $k == 0 or $Line_Counter  1 ) {
  print join(\t,@F);
   }

If you are getting blank lines and just want to eliminate them, then test
for blank lines by putting this line in your while loop:

  next if /^\s*$/;

This will skip any line consisting only of whitespace. If your definition of
blank line differs from that, please let us know what it is.

Other suggestions:

1. Put 'use strict;' and 'use warnings;' in your program.
2. Use the $. built-in variable as a line counter.
3. Use join as shown for printing.
4. Improve your indenting for readability.
5. Be more consistent in naming and using variables, as in $k and
$Line_Counter.

Good luck!



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




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

2011-09-15 Thread Shawn H Corey

On 11-09-15 01:07 AM, Jeff Pang wrote:




15 сентября 2011, 08:38 от Rajeev Prasadrp.ne...@yahoo.com:

I am now using:

my @outfiles = `thecalledscript.pl $filename`;

i am getting right results.

now question is: is this the best method in terms of efficiency?



Not the good way.
It's better to write the called script as a module, then use or require this 
module in main script and call the methods in the module.

--
   Jeff Pang
   jeffp...@mail.ru


A better way, IMHO, if you can't move it to a module, is to use `open`.

open my $fh, '-|', 'thecalledscript.pl' or die could not pipe from 
thecalledscript.pl: $!\n;



--
Just my 0.0002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early  often.

Eliminate software piracy:  use only FLOSS.

Make something worthwhile.  -- Dear Hunter

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




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

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


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

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

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




  1   2   3   4   5   6   7   8   9   10   >