[32078] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3342 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 2 06:09:25 2011

Date: Sat, 2 Apr 2011 03:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 2 Apr 2011     Volume: 11 Number: 3342

Today's topics:
    Re: How do I pass values from a .pl to a .pm. <RedGrittyBrick@spamweary.invalid>
    Re: How do I pass values from a .pl to a .pm. <jurgenex@hotmail.com>
    Re: Search script to index dynamic pages <glex_no-spam@qwest-spam-no.invalid>
    Re: Search script to index dynamic pages <rdw204@gmail.com>
    Re: Search script to index dynamic pages <glex_no-spam@qwest-spam-no.invalid>
    Re: Search script to index dynamic pages <willem@toad.stack.nl>
    Re: Search script to index dynamic pages <rdw204@gmail.com>
    Re: Search script to index dynamic pages <jimsgibson@gmail.com>
    Re: Search script to index dynamic pages <glex_no-spam@qwest-spam-no.invalid>
    Re: Search script to index dynamic pages <lawrence@cluon.com>
    Re: Search script to index dynamic pages <jurgenex@hotmail.com>
    Re: split a special character stored in variable <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 01 Apr 2011 16:51:35 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: How do I pass values from a .pl to a .pm.
Message-Id: <4d95f467$0$12170$fa0fcedb@news.zen.co.uk>

On 01/04/2011 07:50, Ironhide wrote:
> With the code below how do I send the value of $value_to_pass to A.pm,
> so that sub-routines in A.pm can use them?
>
> A.pm
> ====
>
> package A;
>
> ....
> ....
> Do something with the value that I got from the perl script
>
> test.pl
> =====
> use A;
>
> my $value_to_pass= get_value(...);
>
> sub get_value{
> ....
> ....
> return $value
> }
>

See answers from Henry Law & Tad McClellan

In addition, what you might want to do is make A.pm be object-oriented. 
Read `perldoc perltoot`

Then test.pl can do

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

     #
     # "send the value of $value_to_pass to A.pm"
     #
     my $value_to_pass = 42;
     my $a = A->new($value_to_pass);

     #
     # "sub-routines in A.pm can use [it]"
     #
     $a->foo();
     $a->bar();

See the tutorial I referred to for details.

-- 
RGB


------------------------------

Date: Fri, 01 Apr 2011 19:56:32 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How do I pass values from a .pl to a .pm.
Message-Id: <rs3dp6hiqrsqud8o4h5m55jgkugd8o2e7m@4ax.com>

Ironhide <gourabbaksi@gmail.com> wrote:
>With the code below how do I send the value of $value_to_pass to A.pm,
>so that sub-routines in A.pm can use them?
>
>A.pm
>====
>
>package A;
>
>....
>....
>Do something with the value that I got from the perl script

sub Do_something_with_the_value_that_I_got_from_the_perl_script {
	my $value = shift;
	......
}

>
>test.pl
>=====
>use A;
>
>my $value_to_pass= get_value(...);

Do_something_with_the_value_that_I_got_from_the_perl_script($value_to_pass);

>sub get_value{
>....
>....
>return $value
>}
>
>~hanks for your help in advance
>_gourab


------------------------------

Date: Fri, 01 Apr 2011 09:09:39 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Search script to index dynamic pages
Message-Id: <4d95dca4$0$4356$815e3792@news.qwest.net>

Rob wrote:
[...]
> ################################################################################
> #!/usr/bin/perl -w
> use CGI qw(:all);
> use LWP::Simple;
> 
> BEGIN {
>         print "Content-type: text/plain\n\n";
>         $SIG{__WARN__} = sub { print @_ };
>         $SIG{__DIE__} = sub { print @_ unless $^S };
> }
>   my $data = get("http://www.samplesite.org");
> 
>   open (CF2, "testtext.txt");
Ahhhh.. that's (possibly) opening 'testtext.txt' for reading.


>   print CF2 "$data";
Not writing.

Add some error checking and open it for write.

>   close(CF2);
> ################################################################################
> 
> Like I said, it works on my computer but not on the server.
Doubtful, unless 'works' means it doesn't create a file.


------------------------------

Date: Fri, 1 Apr 2011 08:16:08 -0700 (PDT)
From: Rob <rdw204@gmail.com>
Subject: Re: Search script to index dynamic pages
Message-Id: <4fd952b5-ee30-465d-bb97-a7198e51bdc0@e9g2000vbk.googlegroups.com>

On Apr 1, 3:09=A0pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:

>
> Ahhhh.. that's (possibly) opening 'testtext.txt' for reading.

I had deleted the path for the purposes of posting it to this forum
and in the process deleted the ">" at the start, my mistake!

> Doubtful, unless 'works' means it doesn't create a file.

It is creating a file, but leaving it empty - I'm awaiting a response
from my host now about their perl version.

Rob


------------------------------

Date: Fri, 01 Apr 2011 11:12:13 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Search script to index dynamic pages
Message-Id: <4d95e8e4$0$46851$815e3792@news.qwest.net>

Rob wrote:
> On Apr 1, 3:09 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
> 
>> Ahhhh.. that's (possibly) opening 'testtext.txt' for reading.
> 
> I had deleted the path for the purposes of posting it to this forum
> and in the process deleted the ">" at the start, my mistake!

OK.. and what if the open failed????  Add some simple error checking!

> 
>> Doubtful, unless 'works' means it doesn't create a file.
> 
> It is creating a file, but leaving it empty - I'm awaiting a response
> from my host now about their perl version.

Why does your version of perl matter?

Since you're saying it works when you run it, but not when executed
as a CGI, than the first thing I'd look at is a permission
problem.  Back-up a bit, and simplify your problem. Change your
script to simply open the file you want to write to (for write),
print something if open fails, and write something to it. That's all.
Does that work?

A very basic example:

use CGI qw( header );
print header;
my $file = '/some/path/to/file';
if ( open( my $fh, '>', $file ) )
{
	print $fh 'Testing 123';
	close $fh;

	open( my $o, '<', $file );
	print "content of $file: ", <$o>;
	close( $o );
	
}
else
{
	print "opening $file for write failed: $!";
}




------------------------------

Date: Fri, 1 Apr 2011 16:38:43 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: Search script to index dynamic pages
Message-Id: <slrnipbvsj.2n2g.willem@toad.stack.nl>

Rob wrote:
) On Mar 31, 8:50?pm, Willem <wil...@toad.stack.nl> wrote:
)
)> Dump LWP::Simple, and code it using LWP::UserAgent
)>
)> use LWP::UserAgent;
)
) That has helped to show me that it is a matter of the request timing
) out. I imagine this may be because of a security feature which is not
) allowing a script within the site to download itself?

Sounds unlikely.  Especially if you're getting a timeout.
Timeouts usually mean firewalls silently dropping packets.

Have you tried using 'localhost' in place of the server name ?

) I have tried
) changing the IP address of the UserAgent using:
)
) $ua->local_address("10.10.10.10");

That's not likely to help, IMO.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


------------------------------

Date: Fri, 1 Apr 2011 09:44:08 -0700 (PDT)
From: Rob <rdw204@gmail.com>
Subject: Re: Search script to index dynamic pages
Message-Id: <5a6849c8-6cb5-410e-a5ae-aa0391ea1fbe@p16g2000vbi.googlegroups.com>

On Apr 1, 5:12=A0pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:
> OK.. and what if the open failed???? =A0Add some simple error checking!

The open didn't fail, it left me with an empty text file. The only
error I get when running the script is a timeout.

> Why does your version of perl matter?

The version of Perl matters because I am trying to use LWP::UserAgent,
and the version of LWP::UserAgent on my server does not apparently
include the local_address function. I was hoping to use this as
currently when I try to get a page (using LWP::UserAgent) it is timing
out when running from the server, but working when I run from my own
computer. As this is an indexing routine, I would like it to work from
the server.

> Back-up a bit, and simplify your problem. Change your
> script to simply open the file you want to write to (for write),
> print something if open fails, and write something to it. That's all.
> Does that work?

Thanks for the example but it is not a file permission problem, I have
many scripts which read and write files on this server, none of which
are problematic.

Rob


------------------------------

Date: Fri, 01 Apr 2011 10:09:53 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Search script to index dynamic pages
Message-Id: <010420111009538376%jimsgibson@gmail.com>

In article
<6eddef77-52d1-4289-9ca3-16d333434b9e@d28g2000yqf.googlegroups.com>,
Rob <rdw204@gmail.com> wrote:

> On Mar 31, 8:50 pm, Willem <wil...@toad.stack.nl> wrote:
> 
> but I am told that the method "local_address" can't be located through
> the UserAgent package. After looking this up, it would appear that the
> version of Perl is out of date on the server.

Here is a program I stole many years ago to print out server Perl
information. It probably depends upon the server being linux, but it
may be possible to adapt it to other environments:


#!/usr/bin/perl -T
use strict;
use File::Find;
use File::Basename;

my $debug;

# untaint path
$ENV{'PATH'} = '/usr/bin';

# get perl version
my $perlout = `perl -v`;
my $perlver;
if( $perlout =~ m/This is perl, v([\d.]+) built for/s ) {
  $perlver = $1;
}
  

print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>Perl Environment</TITLE></HEAD>\n";
print "<BODY>\n";
print "<h1>Perl Version:</h1>\n";
print "Perl version is $perlver<br>\n" if $perlver;
print "<pre>\n";
print "$perlout\n";
print `perl -V`;
print "</pre>\n";
print "<H1>Perl Modules Installed:</H1>\n";
my( %modules, %seen );
my @subdirs = qw( i386-linux-thread-multi i686-linux );
my( $dirlen, $curdir);
for my $incdir ( @INC ) {
  $curdir = $incdir;
  $dirlen = length($incdir);
  print "\n<br>Look in $incdir ($dirlen):<br>\n\n" if $debug;
  find( {wanted=>\&add_module, no_chdir=>1}, $incdir);
}

print "<p><table border=1 cellspacing=2 cellpadding=4>\n";
print "<tr><th>Module</th><th>Location</th></tr>\n";
foreach my $file ( sort keys %modules ) {
  print "<tr><td>$file</td><td>$modules{$file}</td></tr>\n";
}
print "</table>\n";
print "</BODY></HTML>\n";
exit (0);
  
sub add_module
{
  # only include once
  return if $seen{$File::Find::name}++;
  
  # only include Perl modules ending with '.pm'
  return unless /\.pm$/;
  
  # eliminate unless belongs to active Perl version
  if( $perlver ) {
    return unless /$perlver/;
  }

  #return unless /site/;
  print "  found $_<br>\n" if $debug;
  my $name;
  $name = substr($File::Find::name,$dirlen+1,-3);
  my $loc = substr($File::Find::name,0,$dirlen);
  print "name=$name, loc=$loc<br>\n" if $debug;
  $name =~ s/\//::/g;
  print "    saving &quot;$name&quot; => &quot;$loc&quot;<br>\n" 
    if $debug;
  $modules{$name} = $loc;

}

-- 
Jim Gibson


------------------------------

Date: Fri, 01 Apr 2011 13:49:08 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Search script to index dynamic pages
Message-Id: <4d960dab$0$46842$815e3792@news.qwest.net>

Rob wrote:
> On Apr 1, 5:12 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
>> OK.. and what if the open failed????  Add some simple error checking!
> 
> The open didn't fail, it left me with an empty text file. The only
> error I get when running the script is a timeout.
> 
>> Why does your version of perl matter?
> 
> The version of Perl matters because I am trying to use LWP::UserAgent,
> and the version of LWP::UserAgent on my server does not apparently
> include the local_address function. I was hoping to use this as
> currently when I try to get a page (using LWP::UserAgent) it is timing
> out when running from the server, but working when I run from my own
> computer.

Still the version of perl really doesn't matter.  The version of
that module might, however you can find that version yourself:

use LWP::UserAgent;
print $LWP::UserAgent::VERSION;

or to see if a method 'can' be called:

my $lwp = LWP::UserAgent->new();
print "local_address is available." if $lwp->can( 'local_address' );


> As this is an indexing routine, I would like it to work from
> the server.



No idea why you want to 'index' something through a CGI, but.... Do you
have shell access to the server?  If you do, then connect to that 
machine, using ssh/telnet/whatever, and do everything from that machine. 
Try 'telnet localhost 80'  Do you get a connection?  I guess the server 
could not be allowing connections to port 80 from itself.  If you do
get a connection, then using LWP::Debug might help figure out the
problem, or use the debugger and step through your program, to
see what's happening, or not happening.  There are a lot of possible
problems, working with someone who owns the machine is probably your
best bet.


> 
>> Back-up a bit, and simplify your problem. Change your
>> script to simply open the file you want to write to (for write),
>> print something if open fails, and write something to it. That's all.
>> Does that work?
> 
> Thanks for the example but it is not a file permission problem, I have
> many scripts which read and write files on this server, none of which
> are problematic.

OK.  I haven't been following this very closely.  That's usually a very
common problem.


------------------------------

Date: Fri, 01 Apr 2011 12:52:37 -0600
From: Lawrence Statton <lawrence@cluon.com>
Subject: Re: Search script to index dynamic pages
Message-Id: <871v1lpzwq.fsf@cluon.com>

Rob <rdw204@gmail.com> writes:
>> Why does your version of perl matter?
>
> The version of Perl matters because I am trying to use LWP::UserAgent,
> and the version of LWP::UserAgent on my server does not apparently
> include the local_address function. 


Would not then, the version of LWP::UserAgent (and it's ascendants) be
a much more interesting datum?

--L



------------------------------

Date: Fri, 01 Apr 2011 19:59:02 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Search script to index dynamic pages
Message-Id: <p34dp6hjd19mooq5mg2rhnned0tm710d81@4ax.com>

Rob <rdw204@gmail.com> wrote:
>I am now able to 'get' a page when I run the script from my own
>computer - it successfully downloads the page and I can do what I like
>with the data. 

Great! This means your Perl problem is solved. 

Anything else is something else, like e.g. web server config issues,
missing modules, incorrect use of CGI, ... that list goes on and on.

jue


------------------------------

Date: Fri, 01 Apr 2011 09:08:40 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: split a special character stored in variable
Message-Id: <87hbai6p3r.fsf@lifelogs.com>

On Fri, ***1 Apr*** 2011 12:29:40 -0700 "ela" <ela@yantai.org> wrote: 

e> When I enter the character dot .
e> I find that perl cannot handle properly. It seems that I can't simply escape 
e> add a backslash to escape whatever input delimiter. Is there any solution 
e> for this problem?

e> $delimiter = <STDIN>;
e> chomp $delimiter;

e> @subcells = /$delimiter/, $line;

As Perl really, incredibly, lacks full out-of-ligature spacing,
you can't use the "." character.  It's a language limitation.  You're
supposed to use Unicode instead.

Ted


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3342
***************************************


home help back first fref pref prev next nref lref last post