[26846] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8869 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 19 18:05:31 2006

Date: Thu, 19 Jan 2006 15:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 19 Jan 2006     Volume: 10 Number: 8869

Today's topics:
    Re: randomly choose some uniq elements of an array <news@chaos-net.de>
        Reference Confusion <bob@dont.spam.me>
    Re: Validating massive amounts of external links <glex_no-spam@qwest-spam-no.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 19 Jan 2006 23:20:08 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: randomly choose some uniq elements of an array
Message-Id: <slrndt044o.605.news@maki.homeunix.net>

xhoster@gmail.com wrote :
> Martin Kissner <news@chaos-net.de> wrote:

>> I want to choose a number of files from a directory randomly.
>
> Is "a number" always going to be 3, or at least small?

For the purpose I need the script now, it's always 3.
I had a working solution. I mainly posted to expand my understanding of
Perl.

> Apparently you have read the FAQ.  So why did you implement the method the
> FAQ said was bad, rather than one of the methods that it said were good?
> Reading the FAQ so that you can do exactly what they tell you *not* to do
> seems like an odd programming strategy.

I needed the script for a CGI based website (for showing random images
of the alps to be precise ;) )
Implemented the method wich I understood quickly enough to go on.
Since my array is not very large I was satisfied for the moment.

Thank you for your feedback.
Martin

-- 
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'


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

Date: Thu, 19 Jan 2006 19:05:15 GMT
From: Bob <bob@dont.spam.me>
Subject: Reference Confusion
Message-Id: <pan.2006.01.19.19.05.07.841467@dont.spam.me>

The perl scritpt below is attempting to set some variables from the
contents of a datbase. I can make it work fine if I explicitly and
directly set each variable by name. Because, unlike the demo script below,
there are many variables I tried to be clever with a loop and references.

It almost works.

The print statement within the loop shows that I am getting the correct
data and putting it into a variable with a the name I want, that is a name
that matches the database field name. But, once outside the loop the
contents of the variable disappear or perhaps there is a scoping problem
and I never set the right variable in the first place.

Yes, I am aware that this techniqueue can be unsafe.

I hope the following comes through without getting line-wrapped!

============================= the script =========================

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

my $DB_CONNECT="DBI:Pg:dbname=stable-db";
my $DB_USER="postgres";
my $DB_PASS="passwd";
my $dbh = DBI->connect($DB_CONNECT, $DB_USER, $DB_PASS);

my $id=561;
my $title;

my $query = "SELECT title FROM jobs WHERE id = $id";
my $sth = $dbh->prepare($query);
$sth->execute;

while ( my $row_hash = $sth->fetchrow_hashref ) {
    foreach my $key (sort keys %$row_hash) {
        no strict 'refs';
        $row_hash->{$key} and $$key=$row_hash->{$key} or $$key="";
        print "Here is $key: $$key\n";
    }
    if ( ! $title ) { print "Where did \$title go?\n"; }
    else { print "Title is still $title\n"; }
}

=====================================================================================

Output:

Here is title: My favorite job title
Where did $title go?


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

Date: Thu, 19 Jan 2006 16:39:23 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Validating massive amounts of external links
Message-Id: <wyUzf.35$rc5.790@news.uswest.net>

Lars Haugseth wrote:
> I have a database with a table containing (among others) the columns
> URL, STATUS and LASTCHECKED. Stored in the table are thousand of records
> containg links to external resources (all using the HTTP protocol.)


Randal has an article about checking bookmarked links, which might help:

http://www.stonehenge.com/merlyn/UnixReview/col56.html


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

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 V10 Issue 8869
***************************************


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