[30399] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1642 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 14 14:09:47 2008

Date: Sat, 14 Jun 2008 11:09:10 -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, 14 Jun 2008     Volume: 11 Number: 1642

Today's topics:
    Re: calling external program tiff2pdf <john1949@yahoo.com>
    Re: calling external program tiff2pdf <rvtol+news@isolution.nl>
    Re: calling external program tiff2pdf <john1949@yahoo.com>
    Re: Checking if an object inherits from class T <thepoet_nospam@arcor.de>
    Re: Checking if an object inherits from class T <ben@morrow.me.uk>
    Re: Deleting old files using stat <bill@ts1000.us>
    Re: FAQ 5.38 How do I select a random line from a file? <hjp-usenet2@hjp.at>
    Re: How Does One Implement a Timer in Perl? <hjp-usenet2@hjp.at>
    Re: How Does One Implement a Timer in Perl? <jurgenex@hotmail.com>
    Re: How Does One Implement a Timer in Perl? <ben@morrow.me.uk>
    Re: How Does One Implement a Timer in Perl? <jurgenex@hotmail.com>
    Re: Idle thought about bless <rvtol+news@isolution.nl>
    Re: Learning Perl <dragnet\_@_/internalysis.com>
    Re: LWP::Simple getstore with absolute path not working <ben@morrow.me.uk>
    Re: LWP::UserAgent proxy issues <ced@blv-sam-01.ca.boeing.com>
    Re: sorting a hash / 2008-06-01 <hjp-usenet2@hjp.at>
    Re: sorting a hash / 2008-06-01 <dave@nospam.deezee.org>
    Re: Time and again <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 14 Jun 2008 12:22:18 +0100
From: "John" <john1949@yahoo.com>
Subject: Re: calling external program tiff2pdf
Message-Id: <g309l8$2ev$1@news.albasani.net>


"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message 
news:Xns9ABCB90643395asu1cornelledu@127.0.0.1...
> "John" <john1949@yahoo.com> wrote in
> news:g2tvd1$epa$1@news.albasani.net:
>
>> Manage to crack it.  You need to place all parameters in quotes
>> including the -o.
>>
>> system ("tiff2pdf","-o","$newfile","$filename")
>
> Nope, you misunderstand what you did here. The quotation marks above are
> not important. What is important is the fact that you passed system a LIST
> rather than a single string which by-passed the shell. I am assuming the
> actual $newfile and $filename contained some characters that were
> problematic for the shell.
>
> perldoc -f system
>
> Read the documentation for the functions you use.
>
> Sinan
>
> -- 
> A. Sinan Unur <1usa@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:
> http://www.rehabitation.com/clpmisc/

Hi

I always read the documentation whenever I have a problem with a particular 
construct.  Well, at least my Perl nutshell.
$newfile and $filename only contained fred.tiff and john.pdf.
What system is expecting is an array.
Thanks for input.

Regards
John




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

Date: Sat, 14 Jun 2008 13:52:18 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: calling external program tiff2pdf
Message-Id: <g30ikm.1hc.1@news.isolution.nl>

John schreef:

> my $filename="fred.tiff";
> my $newfile="john.pdf";
> system ("tiff2pdf -o $newfile $filename");
>
> There is no conversion.
>
> I've tried "./tiff2pdf" also.

Then the problem is in the part that you didn't show, or you didn't
copy/past the part literally.

If you for example used single quotes in the real version, that would
explain it.

What did Dan's code show you?

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Sat, 14 Jun 2008 17:15:25 +0100
From: "John" <john1949@yahoo.com>
Subject: Re: calling external program tiff2pdf
Message-Id: <g30qqr$2cu$1@news.albasani.net>


"Dr.Ruud" <rvtol+news@isolution.nl> wrote in message 
news:g30ikm.1hc.1@news.isolution.nl...
> John schreef:
>
>> my $filename="fred.tiff";
>> my $newfile="john.pdf";
>> system ("tiff2pdf -o $newfile $filename");
>>
>> There is no conversion.
>>
>> I've tried "./tiff2pdf" also.
>
> Then the problem is in the part that you didn't show, or you didn't
> copy/past the part literally.
>
> If you for example used single quotes in the real version, that would
> explain it.
>
> What did Dan's code show you?
>
> -- 
> Affijn, Ruud
>
> "Gewoon is een tijger."
>

Hi

I cut and pasted.  The solution is you need to give a list as I mentioned 
earlier.
Many thanks for your input.
Regards
John

You make great Gazelle bicycles.









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

Date: Sat, 14 Jun 2008 15:29:29 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Checking if an object inherits from class T
Message-Id: <4853c7d5$0$6554$9b4e6d93@newsspool3.arcor-online.net>

Koszalek Opalek wrote:
> I am using objects of class T and objects of
> other classes that inherit from T. Somewhere
> in my code I need to check if an object is of
> class T or of any other class that inherits
> from T.

You can use Class->isa() (see "perldoc UNIVERSAL"):

if( ref($obj)->isa('T') )
{
   # class is T or inherits from it
}

HTH
-Chris


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

Date: Sat, 14 Jun 2008 16:55:10 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Checking if an object inherits from class T
Message-Id: <u76di5-t44.ln1@osiris.mauzo.dyndns.org>


Quoth Christian Winter <thepoet_nospam@arcor.de>:
> Koszalek Opalek wrote:
> > I am using objects of class T and objects of
> > other classes that inherit from T. Somewhere
> > in my code I need to check if an object is of
> > class T or of any other class that inherits
> > from T.
> 
> You can use Class->isa() (see "perldoc UNIVERSAL"):
> 
> if( ref($obj)->isa('T') )
> {
>    # class is T or inherits from it
> }

*NO*. Use $obj->isa('T') directly, otherwise objects can't override it
if they need to.

Ben

-- 
  The cosmos, at best, is like a rubbish heap scattered at random.
                                                           Heraclitus
  ben@morrow.me.uk


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

Date: Sat, 14 Jun 2008 01:24:47 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: Deleting old files using stat
Message-Id: <af375fd4-f58b-4af4-8589-f62db2b08c81@2g2000hsn.googlegroups.com>

On Jun 13, 11:20=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Bill H <b...@ts1000.us>:
>
> > I am thinking of using the "atime" (last access time in seconds since
> > the epoch) value returned by stat($filename) to find files (session
> > ids created by my program) that have not been accessed in 24 hours and
> > delete them.
>
> > But before I do this I thought I would ask if there was a better way
> > than itterating over all the files in a folder (could be 1000's of
> > them if the site is busy) and running stat on each and determining if
> > 24 hours has passed?
>
> Nope. About the only other option would be running some daemon that used
> FAM or some other change-notify system to keep track of which files were
> opened, but that would almost certainly be more expensive.
>
> > The other question I had, if I do end up doing this, I should be able
> > to determine if 24 hours has passed if I subtract the atime from time
> > to get the number of seconds passed since it was last accessed,
> > correct?
>
> The -A operator is provided for exactly this sort of job.
>
> Ben
>
> --
> =A0 =A0Although few may originate a policy, we are all able to judge it.
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0Pericles of Athens, c.430 B.C.
> =A0 b...@morrow.me.uk

Thanks Ben. I wanted to ask to be sure. There has been a few times
where I have spent hours perfecting a routine only to find out that
there was a perl command I didnt know about that did the same thing

Bill H


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

Date: Sat, 14 Jun 2008 10:36:20 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 5.38 How do I select a random line from a file?
Message-Id: <slrng570o4.2gh.hjp-usenet2@hrunkner.hjp.at>

On 2008-06-09 20:00, xhoster@gmail.com <xhoster@gmail.com> wrote:
> Yep, and this is the algorithm that the FAQ gives.  But some people are
> not happy with it.  So you have the progression:
>
> 1) naive: read the file once to count the lines, and again to pick
> a random line out of it.  You need to read the file, on average, 1.5 times.

Nope. 1 + l_1/l_f times, where l_1 is the length of the line you are
going to read and l_f is the length of the file. If the file contains
many lines, l_1/l_f will be approximately zero, so you have to read it
about once.


> 2) The reservoir algorithm that the FAQ gives.  This requires reading the
> file exactly once.
>
> If you are dealing with a variable-line-length text file never seen before
> and are unwilling to compromise on randomness, I don't think it is possible
> to do better than this.

Right.


> 3) If you are willing to compromise by preprocessing the file--either into
> something else or building an auxiliary structure--or having longer lines
> be more likely to be chosen than shorter lines, then of course you can do
> better than reading the entire file even once (per execution).  I think
> that is outside the scope of the FAQ, but it is what people decided to
> discuss.

I think that's a more realistic approach. How often do you need to
choose exactly one random line from a file which you've never seen
before and will never see again? When you need to get two random lines
from the file building some kind of index is already faster.

	hp



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

Date: Sat, 14 Jun 2008 10:38:50 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How Does One Implement a Timer in Perl?
Message-Id: <slrng570sq.2gh.hjp-usenet2@hrunkner.hjp.at>

["Followup-To:" header set to comp.lang.perl.misc.]
On 2008-06-13 11:11, Jürgen Exner <jurgenex@hotmail.com> wrote:
> fishfry <BLOCKSPAMfishfry@your-mailbox.com> wrote:
>>In article <1194371465.172543.212450@e9g2000prf.googlegroups.com>,
>> kvnsmnsn@hotmail.com wrote:
>>> Is there a way in Perl to [...] to suspend execution until five
>>> seconds have past or until a response has come, whichever happens
>>> first?  
>
> Your Question is Asked Frequently: perldoc -q timeout

However, that entry doesn't mention select, which seems to be more
appropriate to what the OP has in mind.

	hp


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

Date: Sat, 14 Jun 2008 11:58:09 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How Does One Implement a Timer in Perl?
Message-Id: <egc754h1p2qdtf6el9ffdrpssqvl8pu8ef@4ax.com>

"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>["Followup-To:" header set to comp.lang.perl.misc.]
>On 2008-06-13 11:11, Jürgen Exner <jurgenex@hotmail.com> wrote:
>> fishfry <BLOCKSPAMfishfry@your-mailbox.com> wrote:
>>>In article <1194371465.172543.212450@e9g2000prf.googlegroups.com>,
>>> kvnsmnsn@hotmail.com wrote:
>>>> Is there a way in Perl to [...] to suspend execution until five
>>>> seconds have past or until a response has come, whichever happens
>>>> first?  
>>
>> Your Question is Asked Frequently: perldoc -q timeout
>
>However, that entry doesn't mention select, which seems to be more
>appropriate to what the OP has in mind.

???
You lost me. How does select help you to suspend execution for a
specific amount of time?

jue


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

Date: Sat, 14 Jun 2008 16:59:08 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How Does One Implement a Timer in Perl?
Message-Id: <cf6di5-t44.ln1@osiris.mauzo.dyndns.org>


Quoth Jürgen Exner <jurgenex@hotmail.com>:
> "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
> >
> >However, that entry doesn't mention select, which seems to be more
> >appropriate to what the OP has in mind.
> 
> ???
> You lost me. How does select help you to suspend execution for a
> specific amount of time?

select(undef, undef, undef, $timeout) is a standard way of doing
sub-second sleeps.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: Sat, 14 Jun 2008 16:16:33 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How Does One Implement a Timer in Perl?
Message-Id: <7lr754d2f3hs5cqop91e45c3paf03gop4r@4ax.com>

Ben Morrow <ben@morrow.me.uk> wrote:
>Quoth Jürgen Exner <jurgenex@hotmail.com>:
>> "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>> >
>> >However, that entry doesn't mention select, which seems to be more
>> >appropriate to what the OP has in mind.
>> 
>> ???
>> You lost me. How does select help you to suspend execution for a
>> specific amount of time?
>
>select(undef, undef, undef, $timeout) is a standard way of doing
>sub-second sleeps.

Thank you.

Maybe it's worth adding this tidbit to the FAQ entry for timeout?

jue


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

Date: Sat, 14 Jun 2008 13:59:59 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Idle thought about bless
Message-Id: <g30iu3.1gk.1@news.isolution.nl>

fishfry schreef:

> I was wondering, has anyone ever found some clever use for bless,
> other than for doing OO? It might be handy to put your variables into
> named categories that don't correspond to packages, for example.

++clever: 
http://search.cpan.org/~elizabeth/OOB/ 
OOB - out of band data for any data structure in Perl 

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: Sat, 14 Jun 2008 08:15:18 -0500
From: Marc Bissonnette <dragnet\_@_/internalysis.com>
Subject: Re: Learning Perl
Message-Id: <Xns9ABD5E25AA6Fdragnetinternalysisc@216.196.97.131>

Elizabeth Barnwell <elizabethbarnwell@gmail.com> fell face-first on the 
keyboard. This was the result: news:0ac93957-f491-442f-ba40-
37bd3427aaeb@p25g2000hsf.googlegroups.com:

> 
> Ahhh, this is not meant to be spam. This is meant to be a resource to
> help people, and I regret that it hasn't been received that way. If
> you would like to make changes to the cards here you go,
> http://www.yoyobrain.com/learner_subjects/accept/1458

Frankly, I didn't get the impression that you were spamming or shilling, 
though extra promotion to your company is a side-effect :)

You will find that many perl coders are passionate about the language - 
Personally, if you are doing something that will create more of those 
people, good on you. There *is* a lot of good advice here (in clpm) - Take 
it to heart and keep coming back - More importantly, tell your students 
about it, but make sure they also google "How to ask intelligent 
questions" - That alone will help their learning process immensely, if they 
take it to heart. 


-- 
Marc Bissonnette
Looking for a new ISP? http://www.canadianisp.com
Largest ISP comparison site across Canada.


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

Date: Sat, 14 Jun 2008 16:53:23 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: LWP::Simple getstore with absolute path not working
Message-Id: <j46di5-t44.ln1@osiris.mauzo.dyndns.org>


Quoth emrefan <dksleung@hotmail.com>:
> I am using the following line of sort in a batch file to fetch things
> off the network quickly and mostly I have success but if I need to
> indicate an absolute path in the URL, I always get a "not found"
> error.  I have perl 5.8.x, URI.pm 1.36 and URI::URL.pm 5.03 on the XP
> system
> where did the test. Help!
> 
>                     perl -MLWP::Simple -e "getstore( '%1', '%2' );"
> 
> Oh, the exact URL that I tested it was something like this:
>           
> ftp://user:password@some.computer.some.where//dir-under-the-root/some-dir/some-file
> 
> I thought the "//" before "dir-under-the-root" should have it working
> for me, but no.

FTP urls don't work like that. The standard hack is

    ftp://host/%2fdir-under-the-root/some-dir/some-file

where %2f is a url-encoded '/'; but strictly speaking this requires your
FTP server to support a chdir to '/dir-under-the-root' in one go, which
is not required. Most do, however.

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

Date: Sat, 14 Jun 2008 06:27:10 -0700 (PDT)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: LWP::UserAgent proxy issues
Message-Id: <001dbb43-092b-47cf-bb2f-4d35d56ca48c@y22g2000prd.googlegroups.com>

On Jun 12, 4:20 pm, thesussman <silent...@gmail.com> wrote:
> Hello, I have a number of questions regarding the proxy function of
> LWP::UserAgent.
> What is the syntax of inputting proxies? In the official info page, it
> is written ('http', 'http://proxy.sn.no:8001/'), so is the http prefix
> for the proxy address necessary, or I can just specify vanilla IP
> addresses suffixed with ports without the prefix?

No, you'll need a valid URI with a protocol scheme, eg,  http://...

* perldoc URI  for more info about the URI scheme,
  etc.

> The method demonstration in the documentation makes me curious once
> again regarding the format of the proxy addresses: Is a plain IP
> address - 127.0.0.1:80 for example alright, or I have to seek a proxy
> with a dns (for example: los.micros.com:80)? Or maybe the CGI proxies
> you can find for bypassing filters on the web (The ones where you
> input your destination site address at) are enough? I didn't really
> get it.

Yes, eg, http://127.0.0.1:80

* port 80 is default for http and can be omitted

> How can I confirm that the proxifying process succeeded? Is $proxy->proxy('http', '127.0.0.1:80') || if ($proxy->is_success) enough and
>
> does the ->is_success method works on the proxy() function?

No, you'll need a response object:

$resp = $ua->get( ... );
if ( $resp->is_success ) { ... }

--
Charles DeRykus


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

Date: Sat, 14 Jun 2008 09:47:54 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: sorting a hash / 2008-06-01
Message-Id: <slrng56ttb.2gh.hjp-usenet2@hrunkner.hjp.at>

On 2008-06-12 16:10, Dave Saville <dave@nospam.deezee.org> wrote:
> On Thu, 12 Jun 2008 15:57:37 UTC, xhoster@gmail.com wrote:
>> "Dave Saville" <dave@nospam.deezee.org> wrote:
>> > my $site;
>> 
>> You should declare variables in the tightest scope you can, otherwise
>> use strict will be less helpful in finding such scoping problems.
>> 
>> ...
>> 
>> > foreach $site (keys %sites)
>> 
>> it would be better to use "foreach my $site"

Because that would make it clearer what is happening (see below).

>> > {
>> >   print "\nSite: $site\n";
>> >
>> >   foreach my $url (sort by_value keys %{$urls{$site}})
>> >   {
>> >     print "$site $url $urls{$site}{$url}[0] $urls{$site}{$url}[1]\n";
>> >   }
>> > }
>> 
>> The way foreach works, the $site inside the loop is not the same
>> as the $site declared outside the loop.
>
> Ah Ah. I did not know that. Many thanks for pointing it out, that of 
> course explains everything. 
>

What Xho didn't point out is that Perl has two different types of
scoping: Dynamic scoping and lexical scoping.

Lexical scoping is introduced with "my" and works like in most other
programming languages: The variable is visible until the end of the
block - as seen in the source code. So:

     1  #!/usr/local/bin/perl
     2  use warnings;
     3  use strict;
       
     4  my $x = 'X';
     5  for $x (qw(a b c d)) {
     6      foo();
     7  }
     8  print "$x\n";
       
     9  sub foo {
    10      print "$x\n";
    11  }

will print

    X
    X
    X
    X
    X

because the "inner" $x introduced in line 5 is only visible until the closing
brace in line 7, and both the print in line 8 and the print in line 10
will see the "outer" $x introduced in line 4. 

If you omit the "my" in line 5, that doesn't change, because loop
variables are always implicitely scoped to the loop. 

Now, change line 4 to 

     4  our $x = 'X';

and run the script again:

    a
    b
    c
    d
    X

what happened? Now $x is a global variable, and the implicit scoping in
the loop will use dynamic scoping instead of lexical scoping. The $x
inside of the loop is still a different from the $x outside of the loop
(as you can see, the print in line 8 still prints "X"), but "inside of
the loop" now contains subs called from the loop, so the print inside
foo will see the "inner" $x. 

Dynamic scoping is used very little these days because it is confusing
and error-prone: You need to know from where a function is called to
know which variables it is seeing. But it does exist and for some
specialized uses it may even be clearer.

	hp



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

Date: 14 Jun 2008 15:43:16 GMT
From: "Dave Saville" <dave@nospam.deezee.org>
Subject: Re: sorting a hash / 2008-06-01
Message-Id: <fV45K0OBJxbE-pn2-f24reTR0pu4d@localhost>

On Sat, 14 Jun 2008 07:47:54 UTC, "Peter J. Holzer" 
<hjp-usenet2@hjp.at> wrote:

<snip>

> Dynamic scoping is used very little these days because it is confusing
> and error-prone: You need to know from where a function is called to
> know which variables it is seeing. But it does exist and for some
> specialized uses it may even be clearer.

Ah, so there is a subtle difference between "my $thing" and "our 
$thing" when declared outside of any code blocks. ie at the "top" 
level of a script. I had never seen a condition before where one could
tell the difference. "my $thing" at that level *appears* to behave in 
a global fashion in that everything can "see" it. 

Thanks, you learn something new everyday, The trick is not to forget 
it :-)

-- 
Regards
Dave Saville

NB Remove nospam. for good email address


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

Date: Sat, 14 Jun 2008 12:09:53 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Time and again
Message-Id: <dtc754d0494vkifqvielt08ivkrjbkda1o@4ax.com>

"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
[Whatever]

Clearly your ESP::PSI module is far supperior to mine. That's OK, I
don't mind.
But I don't how see how continuing this discussion would serve any
useful purpose. But again, maybe my crystal ball has failed me.

jue


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

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:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#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 1642
***************************************


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