beginners Digest 28 May 2008 16:42:36 -0000 Issue 3467
- From: beginners-digest-help@xxxxxxxx
- Date: Wed, 28 May 2008 22:23:40 +0100
beginners Digest 28 May 2008 16:42:36 -0000 Issue 3467
Topics (messages 100988 through 101017):
First time using Perl & PDF::API2
100988 by: ChrisC
100998 by: Daniel Kasak
101001 by: Dermot
Re: gateway between googlegroups and the list
100989 by: Gunnar Hjalmarsson
100990 by: Chas. Owens
100992 by: Gunnar Hjalmarsson
100993 by: Rob Dixon
100994 by: Chas. Owens
Re: how to plot graphs
100991 by: Rob Dixon
100996 by: itshardtogetone.hotmail.com
100997 by: itshardtogetone.hotmail.com
101003 by: Rob Dixon
Re: Safe list assignment
100995 by: Dr.Ruud
Re: perl execution error
100999 by: John W. Krahn
Getting Segmentation fault
101000 by: Rajnikant
101007 by: Chas. Owens
about SFTP and Thread dependency
101002 by: Rajnikant
101006 by: Paul Johnson
101008 by: Rajnikant
101011 by: Rajnikant
101012 by: Rob Dixon
101013 by: Jenda Krynicky
creating multiple threads in perl
101004 by: perl pra
101005 by: Chas. Owens
101010 by: Rob Dixon
CGI-Ajax-0.701 - How Do I Capture Table Of Data Via Right-Mouse-Click, Then,
'Export to Excel'
101009 by: ken.stephani.baesystems.com
Curses - chgat
101014 by: Anchal Nigam
efficient max() function from sort
101015 by: Ramprasad A Padmanabhan
101016 by: Li, Jialin
101017 by: John W. Krahn
Administrivia:
To subscribe to the digest, e-mail:
<beginners-digest-subscribe@xxxxxxxx>
To unsubscribe from the digest, e-mail:
<beginners-digest-unsubscribe@xxxxxxxx>
To post to the list, e-mail:
<beginners@xxxxxxxx>
----------------------------------------------------------------------
--- Begin Message ---Hi!,
- From: "ChrisC" <gjwpp88@xxxxxxxxx>
- Date: Tue, 27 May 2008 15:10:59 +0100
Not sure if using PDF::API2 is a good choice or not. Little to no
doc.
In the following code I am able to create the first page ok. Not sure
I am creating the next page correctly or not, but it exist when I open
the PDF file. In the "sub paging " I create the next page, but the
script does not print in the next page. Do I have to tell it to print
on page 2? If so how?
How do I add an image, jpg etc.
Thanks,
Jerry
#!/c:\\Perl\\bin\\perl
use strict;
..
..
..
sub paging {
if( $y <= 50 ) {
$col = ( $col == 0 ) ? $colWidth : 0;
$x = 72 + $col;
$y = $ymax - 20;
$page = $pdf->page(++$page) if $col == $colWidth;
# $gfx = $page->gfx ;
$page = $pdf->openpage($page);
}
}
sub sub_header {
my $name = shift;
my $item = shift;
my $product = shift;
my $header = shift;
my $standard = shift;
print "$name*$product*\n";
$ref{ $name }{ type }[0] =~ s/20\'\/40\'/20\' 40\'/;
print FO "\n$ref{ $name }{ type }[0]$standard\n\n$header\n";
$ref{ $item }{ headersub }[ 0 ]++;
$line += 5;
paging;
$fnt = $pdf->corefont('Arial-BoldItalic',-encoding => 'latin1');
$gfx->textlabel( $x, $y -= 20, $fnt, $Mfnt, "$ref{ $name }{ type }
[0]$standard", -color=>[0.2]);
$fnt = $pdf->corefont('Arial-Bold',-encoding => 'latin1');
$gfx->textlabel( $x, $y -= 20, $fnt, $Mfnt, $header, -
color=>[0.2]);
$x = 72 + $col;
}
sub product {
my $cnt = shift;
my $c = shift;
my $product = shift;
my $name = shift;
my $org = shift;
$y -= 10;
$product =~ s/$c/X/i;
my @args = split /X/, $product;
$fnt = $pdf->corefont('Arial',-encoding => 'latin1');
foreach my $v (@args) {
next if( $cnt++ > 2 );
$v =~ s/^\s+//;
$v =~ s/\s+$//;
$v = $v."\""; # "
print FO $v." "x( 8 - length( $v ));
$line++;
paging;
$gfx->textlabel( $x, $y, $fnt, $Mfnt, $v, -color=>[0.2]);
$x += 56;
}
paging;
my ( $xx, $yy ) = split /\./, $ref{ $name }{ WtFt }{ $org }[ 0 ];
if( length( $xx) == 1 ) {
print FO " $ref{ $name }{ WtFt }{ $org }[ 0 ]\n";
$gfx->textlabel( $x, $y, $fnt, $Mfnt, " ".$ref{ $name }{ WtFt }
{ $org }[ 0 ], -color=>[0.2]);
}else{
print FO "$ref{ $name }{ WtFt }{ $org }[ 0 ]\n"; # $line\n";
$gfx->textlabel( $x, $y, $fnt, $Mfnt, $ref{ $name }{ WtFt }
{ $org }[ 0 ], -color=>[0.2]);
}
$x = 72 + $col;
$line++;
return $cnt;
}
sub shape {
my $name = shift;
my $shape = shift;
$pdf = PDF::API2->new(-file => "w:\\sku_$name.pdf");
print FO "$shape\n";
$ref{ $name }{ shape }[ 0 ] = 1;
$line++;
$pdf->mediabox( $xmax, $ymax );
$page = $pdf->page;
$fnt = $pdf->corefont('Arial-Bold',-encoding => 'latin1');
$gfx = $page->gfx;
$gfx->textlabel( $x, $y, $fnt, $Sfnt, $shape, -color=>[0.2]);
}
sub metal {
my $name = shift;
my $metal = shift;
print FO "\n$metal\n";
$ref{ $name }{ metal }[ 0 ] = 1;
$line++;
paging;
$fnt = $pdf->corefont('Arial-BoldItalic',-encoding => 'latin1');
$gfx->textlabel( $x, $y -= 20, $fnt, $Mfnt, $metal, -
color=>[0.2]);
}
--- End Message ---
--- Begin Message ---On Tue, 2008-05-27 at 07:10 -0700, ChrisC wrote:
- From: "Daniel Kasak" <dkasak@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 02:01:24 +0100
Hi!,
Not sure if using PDF::API2 is a good choice or not. Little to no
doc.
Yeah it's very powerful, and *very* poorly documented. What's worse, one
of the best tutorials ( http://rick.measham.id.au/pdf-api2/ ) has a big
photo of John f'n Howard in it. There's no need to immortalise that war
criminal.
In the "sub paging " I create the next page, but the
script does not print in the next page. Do I have to tell it to print
on page 2? If so how?
For each page, you have to set up page dimensions, create new text and
graphics objects, eg:
# Set page dimensions
$page->mediabox( $self->{page_width}, $self->{page_height} );
# Create a new txt object for the page
$self->{txt} = $page->text;
# Set y to the top of the page
$self->{y} = $self->{page_height} - $self->{upper_margin};
# Create a new gfx object for our lines
$self->{line} = $page->gfx;
How do I add an image, jpg etc.
$gfx->image(
$image, # The image
$img_x_pos, # X
$img_y_pos, # Y
$imgdata->{scale_ratio} # scale
);
You might want to look at my project, PDF::ReportWriter. It uses
PDF::API2 to produce reports. It simplifies things considerably, does
page breaking for you, grouping, etc. You can also use it just to render
text ( keep calling $report->render_data with new text ). I use it for
everything from Access-like reports to producing mail-merge letters ( it
does alignment, justification, etc as well ).
I would point you to my webpage, but I accidentally lost everything
during a server upgrade, so you'll have to get it from CPAN. You can
either use it directly, or view the source to see how to use PDF::API2.
Let me know if you have any other questions, feature requests, etc.
Dan
--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2
9922 7989
email: dkasak@xxxxxxxxxxxxxxxxxxxx
website:
http://www.nusconsulting.com.au
--- End Message ---
--- Begin Message ---2008/5/28 Daniel Kasak <dkasak@xxxxxxxxxxxxxxxxxxxx>:
- From: "Dermot" <paikkos@xxxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 08:28:50 +0100
On Tue, 2008-05-27 at 07:10 -0700, ChrisC wrote:
Hi!,
Not sure if using PDF::API2 is a good choice or not. Little to no
doc.
Yeah it's very powerful, and *very* poorly documented. What's worse, one
of the best tutorials ( http://rick.measham.id.au/pdf-api2/ ) has a big
photo of John f'n Howard in it. There's no need to immortalise that war
criminal.
In the "sub paging " I create the next page, but the
script does not print in the next page. Do I have to tell it to print
on page 2? If so how?
For each page, you have to set up page dimensions, create new text and
graphics objects, eg:
# Set page dimensions
$page->mediabox( $self->{page_width}, $self->{page_height} );
# Create a new txt object for the page
$self->{txt} = $page->text;
# Set y to the top of the page
$self->{y} = $self->{page_height} - $self->{upper_margin};
# Create a new gfx object for our lines
$self->{line} = $page->gfx;
How do I add an image, jpg etc.
$gfx->image(
$image, # The image
$img_x_pos, # X
$img_y_pos, # Y
$imgdata->{scale_ratio} # scale
);
You might want to look at my project, PDF::ReportWriter. It uses
PDF::API2 to produce reports. It simplifies things considerably, does
page breaking for you, grouping, etc. You can also use it just to render
text ( keep calling $report->render_data with new text ). I use it for
everything from Access-like reports to producing mail-merge letters ( it
does alignment, justification, etc as well ).
I would point you to my webpage, but I accidentally lost everything
during a server upgrade, so you'll have to get it from CPAN. You can
either use it directly, or view the source to see how to use PDF::API2.
Let me know if you have any other questions, feature requests, etc.
Dan
--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
I have to agree. I really like PDF::API2 but the documentation is a
little poor. I think the guy how created it (Alfred Reibenschuh) moved
on before he had time to write the documentation up. It would be
really cool if someone could come up with a new tutorial. I also
wonder if there is some more features that could be added to the API
now. No one has done any work on it since 2005.
Just a though,
Dp.
--- End Message ---
--- Begin Message ---Gunnar Hjalmarsson wrote:
- From: "Gunnar Hjalmarsson" <noreply@xxxxxxxxx>
- Date: Tue, 27 May 2008 17:48:45 +0100
Jay Savage wrote:
No message should ever be posted to both groups.
Concur.
They exist to serve different needs.
Do they?
any question thatis appropriate to this list will annoy the readers
of CLPM.
That's not true. Well-written beginner-level questions are typically
well received at clpmisc.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--- End Message ---
--- Begin Message ---On Tue, May 27, 2008 at 12:48 PM, Gunnar Hjalmarsson <noreply@xxxxxxxxx>
- From: "Chas. Owens" <chas.owens@xxxxxxxxx>
- Date: Tue, 27 May 2008 18:06:16 +0100
wrote:
snip
snipany question thatis appropriate to this list will annoy the readers of
CLPM.
That's not true. Well-written beginner-level questions are typically well
received at clpmisc.
The problem is that beginners don't tend to ask well-written questions.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--- End Message ---
--- Begin Message ---Chas. Owens wrote:
- From: "Gunnar Hjalmarsson" <noreply@xxxxxxxxx>
- Date: Tue, 27 May 2008 20:33:21 +0100
On Tue, May 27, 2008 at 12:48 PM, Gunnar Hjalmarsson <noreply@xxxxxxxxx>wrote:
snipwell
any question thatis appropriate to this list will annoy the readers ofThat's not true. Well-written beginner-level questions are typically
CLPM.
snipreceived at clpmisc.
The problem is that beginners don't tend to ask well-written questions.
Are you saying that badly written questions are appropriate to this
list? I hope not. ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--- End Message ---
--- Begin Message ---Gunnar Hjalmarsson wrote:
- From: "Rob Dixon" <rob.dixon@xxxxxxx>
- Date: Tue, 27 May 2008 21:13:02 +0100
Chas. Owens wrote:wrote:
On Tue, May 27, 2008 at 12:48 PM, Gunnar Hjalmarsson <noreply@xxxxxxxxx>
wellsnip
any question thatis appropriate to this list will annoy the readers ofThat's not true. Well-written beginner-level questions are typically
CLPM.
snipreceived at clpmisc.
The problem is that beginners don't tend to ask well-written questions.
Are you saying that badly written questions are appropriate to this
list? I hope not. ;-)
Forming a question well is a skill, and is one essential to programming in
any
language. As a beginners' site we should be tolerant here of people who are
unskilled at both defining the problem and forming a question.
Rob
--- End Message ---
--- Begin Message ---On Tue, May 27, 2008 at 3:33 PM, Gunnar Hjalmarsson <noreply@xxxxxxxxx>
- From: "Chas. Owens" <chas.owens@xxxxxxxxx>
- Date: Tue, 27 May 2008 21:17:42 +0100
wrote:
Chas. Owens wrote:I
On Tue, May 27, 2008 at 12:48 PM, Gunnar Hjalmarsson <noreply@xxxxxxxxx>
wrote:
snip
any question thatis appropriate to this list will annoy the readers of
CLPM.
That's not true. Well-written beginner-level questions are typically
well
received at clpmisc.
snip
The problem is that beginners don't tend to ask well-written questions.
Are you saying that badly written questions are appropriate to this list?
hope not. ;-)
Actually, yes. Part of this list's goals are to help beginners become
acclimated to Perl culture. Letting them ask questions poorly and
then trying to help them ask questions in a better way is part of the
mission.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--- End Message ---
--- Begin Message ---itshardtogetone@xxxxxxxxxxx wrote:
- From: "Rob Dixon" <rob.dixon@xxxxxxx>
- Date: Tue, 27 May 2008 19:51:22 +0100
at
How do I plot a graph using perl. On the horizontal x-axis I need to plot
least 1000 points. I cannot use microsoft excel because of the limitationon
the x-axis. Thanks
There is no need to restrict yourself to an Excel row to hold graph x-axis
values. More often a spread*** column will be used to contain the name of
the
variable at the top, followed by a list of values beneath it.
Rob
--- End Message ---
--- Begin Message -------- Original Message -----
- From: <itshardtogetone@xxxxxxxxxxx>
- Date: Tue, 27 May 2008 22:46:10 +0100
From: "yitzle" <yitzle@xxxxxxxxxxxxxxxxxxxxx>
To: <itshardtogetone@xxxxxxxxxxx>
Cc: <beginners@xxxxxxxx>
Sent: Tuesday, May 27, 2008 7:55 AM
Subject: Re: how to plot graphs
You can use a module off CPAN. A quick search gave me this:
http://search.cpan.org/~smorton/Chart-Plot-0.11/Plot.pm
Hi,
Thanks.
I have activeperl 5.10 installed in my windowsXP. Using their PPM-manager,
how do I search for the above module?
Thanks
--- End Message ---
--- Begin Message ---From: "Rob Dixon" <rob.dixon@xxxxxxx>
- From: <itshardtogetone@xxxxxxxxxxx>
- Date: Tue, 27 May 2008 23:10:59 +0100
To: <beginners@xxxxxxxx>
Cc: <itshardtogetone@xxxxxxxxxxx>
Sent: Wednesday, May 28, 2008 2:51 AM
Subject: Re: how to plot graphs
< snip off>
There is no need to restrict yourself to an Excel row to hold graph x-axisof the
values. More often a spread*** column will be used to contain the name
variable at the top, followed by a list of values beneath it.
Rob
Thanks Rob.
In the excel ***, I put the x-values as follows, so each cell in a row
hold a value in the x-axis, henceforth I face some restrictions, so what is
the correct way to input the values if I wish to have up to game1000. The
values are as follows :-
1 2 1 0 1 2 3 2
game1 game2 game3 game4 game5 game6 game7 game8
--- End Message ---
--- Begin Message ---itshardtogetone@xxxxxxxxxxx wrote:
- From: "Rob Dixon" <rob.dixon@xxxxxxx>
- Date: Wed, 28 May 2008 12:01:02 +0100
From: "Rob Dixon" <rob.dixon@xxxxxxx>x-axis
To: <beginners@xxxxxxxx>
Cc: <itshardtogetone@xxxxxxxxxxx>
Sent: Wednesday, May 28, 2008 2:51 AM
Subject: Re: how to plot graphs
There is no need to restrict yourself to an Excel row to hold graph
of thevalues. More often a spread*** column will be used to contain the name
variable at the top, followed by a list of values beneath it.
In the excel ***, I put the x-values as follows, so each cell in a rowhold
a value in the x-axis, henceforth I face some restrictions, so what is thevalues
correct way to input the values if I wish to have up to game1000. The
are as follows :-
1 2 1 0 1 2 3 2
game1 game2 game3 game4 game5 game6 game7 game8
Simply transpose the table so that the row becomes a column of 1000 items.
However, this being a Perl group it is not the place to discuss Excel
spreadsheets! I was just pointing out that you may still be able to use
Excel if
you would prefer.
Rob
--- End Message ---
--- Begin Message ---Ed Avis schreef:
- From: "Dr.Ruud" <rvtol+news@xxxxxxxxxxxx>
- Date: Tue, 27 May 2008 22:35:45 +0100
Perl's list assignment feature is very useful.
sub returns_three_things { return (1, 2, 3) }
my ($x, $y, $z) = returns_three_things();
Often, though, you want to add some error checking. Particularly
when providing an interface that others can call.
# Parameters: first name, last name, birthday.
sub print_person_details {
croak 'pass three arguments' if @_ != 3;
my ($first_name, $last_name, $birthday) = @_;
say "$first_name $last_name was born on $birthday";
}
The extra 'croak' test gives a more friendly error message than 'use
of uninitialized value in ...', which would require the user of the
subroutine to go digging in its code to find what he passed wrongly.
Even in code that's not part of a public interface, you may want to
check that the list has the right size before you do the assignment,
just to catch programmer mistakes early rather than waiting for an
uninitialized value warning later on.
But it's rather a pain to keep checking the list size each time.
When you 'unpack a tuple' in Python the size is checked and an
exception is thrown if it's too big or too small. Is there an
equivalent in Perl? Something like
safe_assign ($a, $b, $c) = @array; # will die if
scalar(@array) != 3
Even if the number of parameters is right, the values of the parameters
might be wrong. So you beter check each value.
perl -we'
sub say { return print $_[0], qq{\n} }
sub print_person_details {
defined or return for @_[0..2];
return say qq{$_[0] $_[1] was born on $_[2].};
}
print_person_details qw{John Johnson Friday afternoon}
or say q{error};
print_person_details qw{Eve Evening}
or say q{error};
'
John Johnson was born on Friday.
error
--
Affijn, Ruud
"Gewoon is een tijger."
--- End Message ---
--- Begin Message ---Irfan.Sayed@xxxxxxxxxxxxx wrote:
- From: "John W. Krahn" <krahnj@xxxxxxxxx>
- Date: Wed, 28 May 2008 04:06:34 +0100
Hi All,
Hello,
I have written one Perl script. Till today I used to run/execute it
properly but suddenly what has happened is it is throwing some strange
error.
Please apply the corrections that I pointed out to you on 13 May 2008
first before you ask for more help. TIA
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--- End Message ---
--- Begin Message ---Hello everyone,
- From: "Rajnikant" <rajnikant_jachak@xxxxxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 07:58:43 +0100
I want to connect my client to multiple servers and download files using
SFTP.
So as to connect and download file from server I'm using seperate thread.
I'm
getting segmentation fault while creating the SFTP connection/Object in
SFTP::New method.
Following is the code snipet:
use threads;
use Net::SFTP;
my $host = 'xx.yy.zz.aa';
my $user = 'usr';
my $password = 'usr123';
my $thread = threads->new (\&ftpThreadEntry,$host,$user,$password);
my $thread1 = threads->new (\&ftpThreadEntry,$host,$user,$password);
sub ftpThreadEntry()
{
my $host_l = shift;
my $usr = shift;
my $passwd = shift;
print( "$host $usr $passwd \n");
my %args = (
"user", $usr,
"password", $passwd
);
my $sftp = Net::SFTP->new($host_l,%args);
if ($sftp)
{
print(" got connected to $host_l now\n");
}
}
$thread->join();
$thread1->join();
after runing this, I'm getting following errors messages:
PARI: *** forbidden at
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Util/SSH2MP.pm line 17.
thread failed to start: PARI: *** unknown type 41. at
/usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/Util/SSH2MP.pm line 17.
Segmentation fault
Could someone please help me out finding whats wrong in code?
Thanks in advance.
~~~~~~~~~~~~~~~~~~~~
Thanks and Best regards,
~ Rajnikant
Software Engg.
Persistent Sys. Ltd.
Ph. +91 98222 04088
DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the
property of Persistent Systems Ltd. It is intended only for the use of the
individual or entity to which it is addressed. If you are not the intended
recipient, you are not authorized to read, retain, copy, print, distribute
or use this message. If you have received this communication in error,
please notify the sender and delete all copies of this message. Persistent
Systems Ltd. does not accept any liability for virus infected mails.
--- End Message ---
--- Begin Message ---On Wed, May 28, 2008 at 2:58 AM, Rajnikant
- From: "Chas. Owens" <chas.owens@xxxxxxxxx>
- Date: Wed, 28 May 2008 13:34:27 +0100
<rajnikant_jachak@xxxxxxxxxxxxxxxx> wrote:
snip
Could someone please help me out finding whats wrong in code?snip
Thanks in advance.
Without looking at the code in detail I would bet that the module is
not thread safe. Try creating the Net::SFTP objects inside the
thread.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--- End Message ---
--- Begin Message ---Hi all,
- From: "Rajnikant" <rajnikant_jachak@xxxxxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 09:03:59 +0100
I was trying to use SFTP in multithreaded application. I observed many
segmentation faults there.
Following is the code snipet:
use threads;
use Net::SFTP;
my $thrId = 1;
my $thread = threads->new (\&ftpThreadEntry,$thrId);
$thrId = 2;
print("Creating second thread \n");
my $thread1 = threads->new (\&ftpThreadEntry,$thrId);
sub ftpThreadEntry()
{
my $ThrId = shift;
print (" Thread $ThrId in ftpThreadEntry func\n");
}
$thread->join();
$thread1->join();
My Observations :
1. If we comment out 'use Net::SFTP' then this code runs fine without
segmentation fault.
2. If we uncomment 'use Net::SFTP', it gives segmentation fault :(.
Can anyone experienced such situation? Is there any dependency in these
modules or
I'm doing it wrong?
Thanks in advance.
~~~~~~~~~~~~~~~~~~~~
Thanks and Best regards,
~ Rajnikant
Software Engg.
Persistent Sys. Ltd.
Ph. +91 98222 04088
DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the
property of Persistent Systems Ltd. It is intended only for the use of the
individual or entity to which it is addressed. If you are not the intended
recipient, you are not authorized to read, retain, copy, print, distribute
or use this message. If you have received this communication in error,
please notify the sender and delete all copies of this message. Persistent
Systems Ltd. does not accept any liability for virus infected mails.
--- End Message ---
--- Begin Message ---On Wed, May 28, 2008 at 01:33:59PM +0530, Rajnikant wrote:
- From: "Paul Johnson" <paul@xxxxxxxx>
- Date: Wed, 28 May 2008 13:32:17 +0100
I was trying to use SFTP in multithreaded application. I observed many
segmentation faults there.
Following is the code snipet:
use threads;
use Net::SFTP;
Is Net::SFTP thread safe?
Are you using a recent version of Perl?
This e-mail may contain privileged and confidential information which isthe property of Persistent Systems Ltd. It is intended only for the use of
the individual or entity to which it is addressed. If you are not the
intended recipient, you are not authorized to read, retain, copy, print,
distribute or use this message. If you have received this communication in
error, please notify the sender and delete all copies of this message.
Persistent Systems Ltd. does not accept any liability for virus infected
mails.
Eek!
--
Paul Johnson - paul@xxxxxxxx
http://www.pjcj.net
--- End Message ---
--- Begin Message ---I'm using perl 5.8.8.
- From: "Rajnikant" <rajnikant_jachak@xxxxxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 14:29:15 +0100
I don't have any clue about whether Net::SFTP is thread safe or not.
But I used Net::SFTP::Foreign instead of Net::SFTP and it started working
:).
Now I'm facing some different problem :(.
If I try calling Net::SFTP::Foreign->ls method in any thread function it
won't work.
Following is the snipet:
use threads;
use Net::SFTP::Foreign;
$Net::SFTP::Foreign::debug = 1;
$remDir = '/var/opt/stcroamcommon/data/ready';
my $thread = threads->new (\&ftpThreadEntry,$host,$user,$password,$cnt);
sub ftpThreadEntry()
{
my $host_l = shift;
my $usr = shift;
my $passwd = shift;
my $id = shift;
my $prot = 1;
my $sftp = undef;
print ("In ftpThreadEntry func thr id $id\n");
my %args = (
"user", $usr,
"password", $passwd,
"more", '-v',
"port", 6789
);
$sftp = Net::SFTP::Foreign->new($host_l,%args);
my $err = $sftp->error(); # I get 'Password not requested as expected:
-1' msg
my $stat = $sftp->status(); # $stat = 'No connection'
if ($sftp)
{
my $files_r=$sftp->ls($remDir); # Here I get nothing in $files_r :(
my $filename;
foreach my $file_r (@$files_r)
{
$filename=$file_r->{filename};
if($filename ne "." && $filename ne "..")
{
$filename=$remoteDir."/".$filename;
print("File name is $filename\n");
if($sftp->get($filename,$filename))
{
print("Returned something \n");
}
else
{
print("=== not returned anything\n");
}
}
}
}
$thread->join();
Do anyone have any guess?
Thanks for replies.
~~~~~~~~~~~~~~~~~~~~
Thanks and Best regards,
~ Rajnikant
Software Engg.
Persistent Sys. Ltd.
Ph. +91 98222 04088
-----Original Message-----
From: Paul Johnson [mailto:paul@xxxxxxxx]
Sent: Wednesday, May 28, 2008 6:02 PM
To: Rajnikant
Cc: beginners@xxxxxxxx
Subject: Re: about SFTP and Thread dependency
On Wed, May 28, 2008 at 01:33:59PM +0530, Rajnikant wrote:
I was trying to use SFTP in multithreaded application. I observed many
segmentation faults there.
Following is the code snipet:
use threads;
use Net::SFTP;
Is Net::SFTP thread safe?
Are you using a recent version of Perl?
This e-mail may contain privileged and confidential information which isthe property of Persistent Systems Ltd. It is intended only for the use of
the individual or entity to which it is addressed. If you are not the
intended recipient, you are not authorized to read, retain, copy, print,
distribute or use this message. If you have received this communication in
error, please notify the sender and delete all copies of this message.
Persistent Systems Ltd. does not accept any liability for virus infected
mails.
Eek!
--
Paul Johnson - paul@xxxxxxxx
http://www.pjcj.net
DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the
property of Persistent Systems Ltd. It is intended only for the use of the
individual or entity to which it is addressed. If you are not the intended
recipient, you are not authorized to read, retain, copy, print, distribute
or use this message. If you have received this communication in error,
please notify the sender and delete all copies of this message. Persistent
Systems Ltd. does not accept any liability for virus infected mails.
--- End Message ---
--- Begin Message ---
- From: "Rajnikant" <rajnikant_jachak@xxxxxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 14:48:46 +0100
Thanks Chas.
I'm able to create connection 'Net::SFTP::Foreign' object and download files
from remote machine
whithout using thread. But when I use thread to do same I get such errors
:(.
Could you please elaborate on how to do these keys setup? Do I need to do
this specifically
Cause these think works if I don't use thread?
~~~~~~~~~~~~~~~~~~~~
Thanks and Best regards,
~ Rajnikant
Software Engg.
Persistent Sys. Ltd.
Ph. +91 98222 04088
-----Original Message-----
From: Chas. Owens [mailto:chas.owens@xxxxxxxxx]
Sent: Wednesday, May 28, 2008 7:09 PM
To: Rajnikant
Subject: Re: about SFTP and Thread dependency
On Wed, May 28, 2008 at 9:29 AM, Rajnikant
<rajnikant_jachak@xxxxxxxxxxxxxxxx> wrote:
snip
$sftp = Net::SFTP::Foreign->new($host_l,%args);snip
my $err = $sftp->error(); # I get 'Password not requested as expected:
-1' msg
my $stat = $sftp->status(); # $stat = 'No connection'
if ($sftp)
{
my $files_r=$sftp->ls($remDir); # Here I get nothing in $files_r :(
my $filename;
If $sftp->error returns a true value then you have an error. The
$sftp->ls method isn't working because of the earlier error. Given the fact
that you are getting "No connection" from $sftp->status, I am willing to bet
you don't have keys setup on the host and local machine.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the
property of Persistent Systems Ltd. It is intended only for the use of the
individual or entity to which it is addressed. If you are not the intended
recipient, you are not authorized to read, retain, copy, print, distribute
or use this message. If you have received this communication in error,
please notify the sender and delete all copies of this message. Persistent
Systems Ltd. does not accept any liability for virus infected mails.
--- End Message ---
--- Begin Message ---Rajnikant wrote:
- From: "Rob Dixon" <rob.dixon@xxxxxxx>
- Date: Wed, 28 May 2008 15:06:55 +0100
I'm using perl 5.8.8.
I don't have any clue about whether Net::SFTP is thread safe or not.
But I used Net::SFTP::Foreign instead of Net::SFTP and it started working
:).
Now I'm facing some different problem :(.
If I try calling Net::SFTP::Foreign->ls method in any thread function it
won't work.
Following is the snipet:
use threads;
use Net::SFTP::Foreign;
$Net::SFTP::Foreign::debug = 1;
$remDir = '/var/opt/stcroamcommon/data/ready';
my $thread = threads->new (\&ftpThreadEntry,$host,$user,$password,$cnt);
sub ftpThreadEntry()
{
my $host_l = shift;
my $usr = shift;
my $passwd = shift;
my $id = shift;
my $prot = 1;
my $sftp = undef;
print ("In ftpThreadEntry func thr id $id\n");
my %args = (
"user", $usr,
"password", $passwd,
"more", '-v',
"port", 6789
);
$sftp = Net::SFTP::Foreign->new($host_l,%args);
my $err = $sftp->error(); # I get 'Password not requested as expected:
-1' msg
my $stat = $sftp->status(); # $stat = 'No connection'
if ($sftp)
{
my $files_r=$sftp->ls($remDir); # Here I get nothing in $files_r :(
my $filename;
foreach my $file_r (@$files_r)
{
$filename=$file_r->{filename};
if($filename ne "." && $filename ne "..")
{
$filename=$remoteDir."/".$filename;
print("File name is $filename\n");
if($sftp->get($filename,$filename))
{
print("Returned something \n");
}
else
{
print("=== not returned anything\n");
}
}
}
}
$thread->join();
First of all, please bottom-post replies to threads in this group, so that
extended threads can remain comprehensible. It is something that is said
almost
every day here and you really should try to be polite.
Secondly, the only obvious bug I can see is that you have assigned to
$remDir
and then used $remoteDir. Bugs like this are inexcusable, as something else
that
is said here almost every day is that you /must/
use strict;
and
use warnings;
on every program that you post here. There are no exceptions.
Thirdly, the code you have posted doesn't compile. It is broken because
there is
a missing closing brace. I can guess where it belongs, but I really
shouldn't
have to.
Finally, you're a C programmer aren't you? Go on, admit it! There is no
reason
for all those nested blocks. Look
foreach my $file (@$files) {
my $filename = $file->{filename};
next unless $filename ne '.' and $filename ne '..';
$filename = "$remoteDir/$filename";
print("File name is $filename\n");
if ($sftp->get($filename, $filename)) {
print("Returned something \n");
}
else {
print("=== not returned anything\n");
}
}
Oh, and don't prototype subroutines. It should be
sub ftpThreadEntry {
:
}
HTH,
Rob
--- End Message ---
--- Begin Message ---From: "Rajnikant" <rajnikant_jachak@xxxxxxxxxxxxxxxx>
- From: "Jenda Krynicky" <Jenda@xxxxxxxxxxx>
- Date: Wed, 28 May 2008 15:07:03 +0100
I was trying to use SFTP in multithreaded application. I observed many
segmentation faults there.
Following is the code snipet:
use threads;
use Net::SFTP;
my $thrId = 1;
my $thread = threads->new (\&ftpThreadEntry,$thrId);
$thrId = 2;
print("Creating second thread \n");
my $thread1 = threads->new (\&ftpThreadEntry,$thrId);
sub ftpThreadEntry()
{
my $ThrId = shift;
print (" Thread $ThrId in ftpThreadEntry func\n");
}
$thread->join();
$thread1->join();
My Observations :
1. If we comment out 'use Net::SFTP' then this code runs fine without
segmentation fault.
2. If we uncomment 'use Net::SFTP', it gives segmentation fault :(.
Can anyone experienced such situation? Is there any dependency in these
modules or
I'm doing it wrong?
The module is most likely not threadsafe ... or uses something that
is not. Try to load it only in one thread and only after the other
thread was created.
Keep in mind that you'll have to use either
require Net::SFTP;
or
eval "use Net::SFTP";
otherwise the module would still be loaded too soon.
Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--- End Message ---
--- Begin Message ---Hi gurus,
- From: "perl pra" <perlpra@xxxxxxxxx>
- Date: Wed, 28 May 2008 12:53:13 +0100
I need to create "n" mulitple threads simaltaneously and all the threads
should do same operation(just like Jmeter).
i have a subroutine
sub printname{
my ($tid)=@_;
print "name is guru tid is $tid\n";
}
all the threads should execute the above subroutine simaltaneoulsy.
Thanks,
siva
--- End Message ---
--- Begin Message ---On Wed, May 28, 2008 at 7:53 AM, perl pra <perlpra@xxxxxxxxx> wrote:
- From: "Chas. Owens" <chas.owens@xxxxxxxxx>
- Date: Wed, 28 May 2008 13:27:46 +0100
Hi gurus,
I need to create "n" mulitple threads simaltaneously and all the threads
should do same operation(just like Jmeter).
i have a subroutine
sub printname{
my ($tid)=@_;
print "name is guru tid is $tid\n";
}
all the threads should execute the above subroutine simaltaneoulsy.
Thanks,
siva
Are you certain you need threads? It sounds like fork will do the job.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--- End Message ---
--- Begin Message ---perl pra wrote:
- From: "Rob Dixon" <rob.dixon@xxxxxxx>
- Date: Wed, 28 May 2008 14:32:02 +0100
I need to create "n" mulitple threads simaltaneously and all the threads
should do same operation(just like Jmeter).
i have a subroutine
sub printname{
my ($tid)=@_;
print "name is guru tid is $tid\n";
}
all the threads should execute the above subroutine simaltaneoulsy.
And what is your question?
Rob
--- End Message ---
--- Begin Message ---I build a table, but, when I try to export to MicroSoft Excel I see
- From: <ken.stephani@xxxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 12:46:52 +0100
Excel start, but then I get a "Web query returned no data" popup.
Thank you very much, in advance, for any help!!
Regards!!
--- End Message ---
--- Begin Message ---Does anyone use curses and the method chgat because I am unable to
- From: "Anchal Nigam" <imthenachoman@xxxxxxxxx>
- Date: Wed, 28 May 2008 15:44:12 +0100
figure out how to use it. I have tried many forms of the method calls
and they all compile but none of them do anything.
Thanks
_Nacho
--- End Message ---
--- Begin Message ---
- From: "Ramprasad A Padmanabhan" <ram@xxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 15:17:34 +0100
I use sort to give the max of an array something like this
-----
my @z = qw(12 24 67 89 77 91 44 5 10);
my $max = ((reverse sort{$a <=> $b} (@z))[0]);
print "MAX = $max\n";
-----------
but when I am interested only in a single max value, I need not sort the
entire array
Is there a more efficient alternative to this
PS: Posts via nntp to nntp.perl.org appear after a long time
Is there a more preferred way of posting here
Thanks
Ram
--- End Message ---
--- Begin Message ---On Wed, May 28, 2008 at 9:17 AM, Ramprasad A Padmanabhan <ram@xxxxxxxxxxxxx>
- From: "Li, Jialin" <jialinli1981@xxxxxxxxx>
- Date: Wed, 28 May 2008 17:40:39 +0100
wrote:
I use sort to give the max of an array something like this
-----
my @z = qw(12 24 67 89 77 91 44 5 10);
my $max = ((reverse sort{$a <=> $b} (@z))[0]);
print "MAX = $max\n";
-----------
but when I am interested only in a single max value, I need not sort the
entire array
Is there a more efficient alternative to this
PS: Posts via nntp to nntp.perl.org appear after a long time
Is there a more preferred way of posting here
Thanks
Ram
--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/
just compare one by one to find the max
my @z = qw(12 24 67 89 77 91 44 5 10);
my $max = $z[0];
map { $max = $_ if ($max < $_); } @z;
print $max;
or use List::Util which provides max subroutine
--- End Message ---
--- Begin Message ---Ramprasad A Padmanabhan wrote:
- From: "John W. Krahn" <krahnj@xxxxxxxxx>
- Date: Wed, 28 May 2008 17:42:23 +0100
I use sort to give the max of an array something like this
-----
my @z = qw(12 24 67 89 77 91 44 5 10);
my $max = ((reverse sort{$a <=> $b} (@z))[0]);
print "MAX = $max\n";
-----------
but when I am interested only in a single max value, I need not sort the
entire array
Is there a more efficient alternative to this
my $max = $z[ 0 ];
for ( @z ) {
$max = $_ if $max < $_;
}
print "MAX = $max\n";
Or:
use List::Util 'max';
my $max = max @z;
print "MAX = $max\n";
PS: Posts via nntp to nntp.perl.org appear after a long time
Is there a more preferred way of posting here
Have you subscribed to the mailing list?
http://lists.cpan.org/showlist.cgi?name=beginners
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--- End Message ---
- Prev by Date: Re: how to plot graphs
- Next by Date: Re: Data::Table error
- Previous by thread: error with repeated matching
- Next by thread: regex question matching dates
- Index(es):