[23259] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5479 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 10 18:05:50 2003

Date: Wed, 10 Sep 2003 15:05:18 -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           Wed, 10 Sep 2003     Volume: 10 Number: 5479

Today's topics:
    Re: "between" function equivalent in Perl? <no@email.com>
    Re: "between" function equivalent in Perl? <sagittaur@ftml.net>
    Re: "between" function equivalent in Perl? <sagittaur@ftml.net>
    Re: "between" function equivalent in Perl? <sagittaur@ftml.net>
    Re: "between" function equivalent in Perl? <mpapec@yahoo.com>
    Re: "between" function equivalent in Perl? <krahnj@acm.org>
    Re: Best ways of using a username & password? <postmaster@castleamber.com>
    Re: Best ways of using a username & password? <syscjm@gwu.edu>
    Re: Best ways of using a username & password? (Tad McClellan)
    Re: Best ways of using a username & password? <asu1@c-o-r-n-e-l-l.edu>
    Re: Best ways of using a username & password? <usenet@expires12.2003.tinita.de>
    Re: Best ways of using a username & password? <asu1@c-o-r-n-e-l-l.edu>
    Re: calculation in string <tcurrey@no.no.no.i.said.no>
    Re: Converting C++ to Perl (Kenny McCarty)
    Re: Counting files <mikeflan@earthlink.net>
    Re: Creating a DSN-less connection to a MySQL database (James Willmore)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Sep 2003 19:36:28 +0100
From: "Brian Wakem" <no@email.com>
Subject: Re: "between" function equivalent in Perl?
Message-Id: <bjnqvd$kt4jn$1@ID-112158.news.uni-berlin.de>


"Alexandra" <sagittaur@ftml.net> wrote in message
news:bjnknd$rk7$1@lumberjack.rand.org...
>
> "Brian Wakem" wrote:
>
> > "Alexandra" wrote:
>
> > > this. Here's what I'm trying to do:
> > >
> > > $mystring = 'aaa @ bbbb @ c @ dd @ eeeeee @ FFFFF=xxxx @ ggg @ h'
> > >
> > > The goal is to extract the 'xxxx' substring between the '=' sign and
the
> > > next whitespace character. (There is no fixed length for the 'xxxx'
> > > substring.)
> > >
> > > Rather than use a series of clunky index and substring calls, does
> anyone
> > > have a better suggestion? If anyone can recommend a good Perl language
> > > reference website (or book) that has some excellent examples of
regular
> > > expressions, that would be helpful too.
> >
> >
> > print $mystring =~ m/=([^\s]+)/;
>
> Thanks for your reply. For some reason this also evaluated to 1, instead
of
> the desired substring. And there is not a "1" character in the initial
> string ($mystring). I tried placing brackets [] around the equal sign and
> still no dice.
>
> The expression seems, somehow, to be evaluating for a truth value. (??)


All of the examples given in the replies to your original message work
absolutely fine.  You are doing something you aren't telling us.  Post your
code.

-- 
Brian Wakem




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

Date: Wed, 10 Sep 2003 11:28:18 -0700
From: "Alexandra" <sagittaur@ftml.net>
Subject: Re: "between" function equivalent in Perl?
Message-Id: <bjnqg3$sq1$1@lumberjack.rand.org>

"Uri Guttman" wrote:

> >>>>> "A" == Alexandra  <sagittaur@ftml.net> writes:
>
>   >> my($match) = $mystring =~ /=(\S+)/;
>
>   A> Thanks for your reply. Unfortunately, I only received a "1" as the
return
>   A> value, as I also did with some of the other suggestions. I'm not sure
if
>   A> this means it's evaluating to Boolean (or why). I did some debugging
to
>   A> ensure $mystring is a valid text value, and it seems to be.
>
> the above will not evaluate to 1. your code is not the same as that line
> of code. wanna bet you don't have () around your $match var?

Yes! That was it, thank you. All of the following 'mysubstr#' expressions
now work perfectly well. (My apologies to original posters for not
understanding this aspect.)

   $mystr = `grep $in{lookup_key} /AAA/bbbb/ccc/dd/eeee.ff`;
   $in{mystr} = $mystr;  #debug
   $from = '=';
   $in{myfrom} = $from;  #debug
   $to = ' ';
   $in{myto} = $to;      #debug

   ($in{mysubstr0}) = $mystr =~ /=(\S+)/;
   ($in{mysubstr1}) = $mystr =~ /=(.*?)\s/;
   ($in{mysubstr2}) = $mystr =~ m/[=]([^\s]+)/;
   ($in{mysubstr3}) = $mystr =~ /$from(.*?)$to/;


I found that most all of the regular expression examples in the Programming
Perl book use shorthand of referring to $_ (thus, not providing an
explicitly named variable at all). The examples that do refer to a named
variable have something like "($foo = $bar) =~ s/this/that;". So, I'd
assumed the parentheses were only needed when using mulitple explicitly
named variables. Good for non-beginners, otherwise difficult to decipher.

>   >> I've heard that "Mastering regular expression" is very good.
>
>   A> We do have some of the O'Reilly books in the office but not that one.
Thank
>   A> you, I'll check it out.
>
> this is covered in perlre, perlretut and perlrequick. you need to learn
> how regexes work in different contexts.

Great, I found them on perldoc.com and will read them.

Btw, the only reference to contexts in Programming Perl focused on lists and
scalar contexts. Nowhere did I see mention of enclosing an assignment
variable in parentheses or why. Though I did find this quote: "You will be
miserable until you learn the difference between scalar and list context,
because certain operators know which context they are in, and return lists
in contexts wanting a list, and scalar values in contexts wanting a scalar."

It's all so clear now...

Anyway, thanks for replying and for the fix.

Alexandra





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

Date: Wed, 10 Sep 2003 11:28:23 -0700
From: "Alexandra" <sagittaur@ftml.net>
Subject: Re: "between" function equivalent in Perl?
Message-Id: <bjnqg9$sq4$1@lumberjack.rand.org>

"Dave Saville" wrote:

> I just cut n pasted the code from previous posts
>
> use strict;
> use warnings;
> my $mystring = 'aaa @ bbbb @ c @ dd @ eeeeee @ FFFFF=xxxx @ ggg @ h';
> my $from = qr/=/; # a "="
> my $to = qr/\s/;  # any white space
> my ( $between) = $mystring =~ /$from(.*?)$to/;
> print "$between\n";
>
>
> Prints xxxx here. Perl 5.8.0 on OS/2. Something odd your end I feel.

Yes, thank you for taking the time. It was indeed the lack of () on my end.

All of the initial suggestions worked once I added them:

   ($in{login0}) = $user_rec =~ /=(\S+)/;
   ($in{login1}) = $user_rec =~ /=(.*?)\s/;
   ($in{login2}) = $user_rec =~ m/[=]([^\s]+)/;
   ($in{login3}) = $user_rec =~ /$from(.*?)$to/;

Alexandra




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

Date: Wed, 10 Sep 2003 11:46:54 -0700
From: "Alexandra" <sagittaur@ftml.net>
Subject: Re: "between" function equivalent in Perl?
Message-Id: <bjnriv$sss$1@lumberjack.rand.org>

"Brian Wakem" wrote:
> "Alexandra" wrote:

> All of the examples given in the replies to your original message work
> absolutely fine.  You are doing something you aren't telling us.  Post
your
> code.

Yes, they do work (see other replies). It was my error with lack of
parentheses around the assignment var. Next time I'll include my code in
initial replies.

Regards,

Alexandra




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

Date: Wed, 10 Sep 2003 21:15:19 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: "between" function equivalent in Perl?
Message-Id: <qjtulv8ig1racmgkaece7vfqi1om79c7ol@4ax.com>

X-Ftn-To: Alexandra 

"Alexandra" <sagittaur@ftml.net> wrote:
>> >$mystring = 'aaa @ bbbb @ c @ dd @ eeeeee @ FFFFF=xxxx @ ggg @ h'
>> >
>> >The goal is to extract the 'xxxx' substring between the '=' sign and the
>> >next whitespace character. (There is no fixed length for the 'xxxx'
>> >substring.)
>>
>> my($match) = $mystring =~ /=(\S+)/;
>
>Thanks for your reply. Unfortunately, I only received a "1" as the return
>value, as I also did with some of the other suggestions. I'm not sure if
>this means it's evaluating to Boolean (or why). I did some debugging to
>ensure $mystring is a valid text value, and it seems to be.

Now when you know that you've been missing (), try to figure out why you've
received "1".

>> >Rather than use a series of clunky index and substring calls, does anyone
>> >have a better suggestion? If anyone can recommend a good Perl language
>> >reference website (or book) that has some excellent examples of regular
>> >expressions, that would be helpful too.
>>
>> I've heard that "Mastering regular expression" is very good.
>
>We do have some of the O'Reilly books in the office but not that one. Thank
>you, I'll check it out.

There are also docs that come bundled with perl(perldoc perlrequick) if you
don't mind staring at your monitor. :)



-- 
Matija


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

Date: Wed, 10 Sep 2003 21:00:57 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: "between" function equivalent in Perl?
Message-Id: <3F5F9105.F2D66B0C@acm.org>

Alexandra wrote:
> 
> "Uri Guttman" wrote:
> 
> > >>>>> "A" == Alexandra  <sagittaur@ftml.net> writes:
> >
> >   >> my($match) = $mystring =~ /=(\S+)/;
> >
> >   A> Thanks for your reply. Unfortunately, I only received a "1" as the return
> >   A> value, as I also did with some of the other suggestions. I'm not sure if
> >   A> this means it's evaluating to Boolean (or why). I did some debugging to
> >   A> ensure $mystring is a valid text value, and it seems to be.
> >
> > the above will not evaluate to 1. your code is not the same as that line
> > of code. wanna bet you don't have () around your $match var?
> 
> Yes! That was it, thank you. All of the following 'mysubstr#' expressions
> now work perfectly well. (My apologies to original posters for not
> understanding this aspect.)
> 
>    $mystr = `grep $in{lookup_key} /AAA/bbbb/ccc/dd/eeee.ff`;

Instead of running an external program for this you can do it in perl
and have better control of error reporting:

my $file = '/AAA/bbbb/ccc/dd/eeee.ff';
open my $fh, '<', $file or die "Cannot open $file: $!"
my $mystr = join '', grep $in{lookup_key}, <$fh>;
close $fh;


>    $in{mystr} = $mystr;  #debug
>    $from = '=';
>    $in{myfrom} = $from;  #debug
>    $to = ' ';
>    $in{myto} = $to;      #debug
> 
>    ($in{mysubstr0}) = $mystr =~ /=(\S+)/;
>    ($in{mysubstr1}) = $mystr =~ /=(.*?)\s/;
>    ($in{mysubstr2}) = $mystr =~ m/[=]([^\s]+)/;
>    ($in{mysubstr3}) = $mystr =~ /$from(.*?)$to/;
> 
> I found that most all of the regular expression examples in the Programming
> Perl book use shorthand of referring to $_ (thus, not providing an
> explicitly named variable at all).

Whenever you see "/regex/" or "$var = /regex/" you can expand them to
"$_ =~ /regex/" and "$var = $_ =~ /regex/" then the "$_ =~" part can be
replaced with whatever scalar variable you want.


> The examples that do refer to a named
> variable have something like "($foo = $bar) =~ s/this/that;".

Because the binding operator (=~) has higher precedence then the
assignment operator (=) the parenthesis are required to assign the
contents of $bar to $foo before the substitution is performed on the
result so that $foo is changed and $bar is not.  Without the parenthesis
the substitution would be performed on $bar first and the result of that
(true or false) would be assigned to $foo.


> So, I'd
> assumed the parentheses were only needed when using mulitple explicitly
> named variables. Good for non-beginners, otherwise difficult to decipher.
> 
> >   >> I've heard that "Mastering regular expression" is very good.
> >
> >   A> We do have some of the O'Reilly books in the office but not that one. Thank
> >   A> you, I'll check it out.
> >
> > this is covered in perlre, perlretut and perlrequick. you need to learn
> > how regexes work in different contexts.
> 
> Great, I found them on perldoc.com and will read them.
> 
> Btw, the only reference to contexts in Programming Perl focused on lists and
> scalar contexts. Nowhere did I see mention of enclosing an assignment
> variable in parentheses or why. Though I did find this quote: "You will be
> miserable until you learn the difference between scalar and list context,
> because certain operators know which context they are in, and return lists
> in contexts wanting a list, and scalar values in contexts wanting a scalar."
> 
> It's all so clear now...

Is that irony?

perlsub.pod explains a bit about the difference between scalar and list
context.

perldoc perlsub



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 10 Sep 2003 20:53:11 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Best ways of using a username & password?
Message-Id: <1063220099.130347@halkan.kabelfoon.nl>

Jürgen Exner wrote:

> Perl does not have cookies

But you can eat them while using it :-)

-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



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

Date: Wed, 10 Sep 2003 15:53:35 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: Best ways of using a username & password?
Message-Id: <3F5F813F.8010402@gwu.edu>

Gary Mayor wrote:
> A. Sinan Unur wrote:
> 
>> Gary Mayor <gary@abertron.co.uk> wrote in
>> news:cmE7b.123$eW.193317@newsfep1-win.server.ntli.net:
>>
>>> Hi,
>>> I'm placing a username and password form on my site but can't decide
>>> on the best way to do it. I've looked at
>>> Apache Session ID
>>> Encrypted cookies
>>> and a couple of other things that are crap. What's the best method of 
>>> doing it. I need them to enter a username and password and I need the 
>>> site to remember there using it and timeout after 20 minutes of
>>> inactivity. Is there an industry standard for doing this?
>>
>>
>>
>> None of this is topical for this group. Try 
>> comp.inforsystems.www.authoring.cgi for general questions, and find 
>> the appropriate group for your server for server-specific questions.
>>
>> You may want to consult the WWW Security FAQ 
>> (http://www.w3.org/Security/Faq/www-security-faq.html) and the Login 
>> Tutorial (http://www.webthing.com/tutorials/LOGIN1.html).
>> Sinan.
>>
> 
> How can this be in the wrong group. This is a Perl Misc group

And your question has nothing to do with Perl.  It is an http
and webserver/CGI question, which is why Sinan pointed you to
comp.inforsystems.www.authoring.cgi.

                        Chris Mattern



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

Date: Wed, 10 Sep 2003 12:25:19 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Best ways of using a username & password?
Message-Id: <slrnblunjv.4d5.tadmc@magna.augustmail.com>

Gary Mayor <gary@abertron.co.uk> wrote:
> A. Sinan Unur wrote:
>> Gary Mayor <gary@abertron.co.uk> wrote in
>> news:cmE7b.123$eW.193317@newsfep1-win.server.ntli.net: 

>>>I'm placing a username and password form on my site but can't decide
>>>on the best way to do it. I've looked at
>>>Apache Session ID
>>>Encrypted cookies


>> None of this is topical for this group.

> How can this be in the wrong group. This is a Perl Misc group and most 
> of the people on here will have there own methods of using passwords. My 


Most of the people here do not use Perl in the CGI environment.

I'm surprised you haven't noticed that in all the time you've been
lurking on this newsgroup.


> topic is about perl I wasn't asking about any other language. 


You weren't asking about Perl either. You were asking about web
servers and the CGI.

People that know about servers and CGI hang out in newsgroups that
discuss servers and CGI.

You have a better chance of getting a good answer if you ask
where the experts hang out.


> Miscellaneous means anything relating to Perl right so why the hell is 
> this in the wrong group. 


Because your questions were about your application, not
about your programming language.


> If people spent less time moaning and more 
> doing this world would be a better place.


So long.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 10 Sep 2003 20:24:10 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Best ways of using a username & password?
Message-Id: <Xns93F2A6DC6304Basu1cornelledu@132.236.56.8>

Gary Mayor <gary@abertron.co.uk> wrote in
news:2NG7b.983$lj5.564143@newsfep2-win.server.ntli.net: 

> A. Sinan Unur wrote:
>> Gary Mayor <gary@abertron.co.uk> wrote in
>> news:cmE7b.123$eW.193317@newsfep1-win.server.ntli.net: 
>> 
>> 
>>>Hi,
>>>I'm placing a username and password form on my site but can't decide
>>>on the best way to do it.

<snip>

>> None of this is topical for this group. Try ...

<snip>

> How can this be in the wrong group. 

 ...

> why the hell is this in the wrong group.

<snip>

> But thanks for the last url that helped.

You are not welcome.

I tried to direct you to some useful resources more relevant to your 
question (without using any harsh language). I think the burden is on 
you, when someone tells you that your post is off-topic, to check the 
charter of the newsgroup to make sure you are in the right place before 
you yell and scream at people.

Sinan.
-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: 10 Sep 2003 20:51:44 GMT
From: Tina Mueller <usenet@expires12.2003.tinita.de>
Subject: Re: Best ways of using a username & password?
Message-Id: <bjo2t0$lavn6$2@ID-24002.news.uni-berlin.de>

A. Sinan Unur wrote:
> None of this is topical for this group. Try 
> comp.inforsystems.www.authoring.cgi for general questions, and find the 
           ^
comp.infosystems.www.authoring.cgi

regards, tina
-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/   \     / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/   \    \ _,_\ __/\ __/_| /__/ perception
- the above mail address expires end of december 2003 -


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

Date: 10 Sep 2003 21:11:25 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Best ways of using a username & password?
Message-Id: <Xns93F2AEDE9B907asu1cornelledu@132.236.56.8>

Tina Mueller <usenet@expires12.2003.tinita.de> wrote in news:bjo2t0$lavn6$2
@ID-24002.news.uni-berlin.de:

> A. Sinan Unur wrote:
>> None of this is topical for this group. Try 
>> comp.inforsystems.www.authoring.cgi for general questions, and find the 
>            ^
> comp.infosystems.www.authoring.cgi
> 
> regards, tina

oooops! thanks for pointing that out.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Wed, 10 Sep 2003 12:33:51 -0700
From: "Trent Curry" <tcurrey@no.no.no.i.said.no>
Subject: Re: calculation in string
Message-Id: <bjnuf7$dm$1@news.astound.net>



-- 
Stan
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:bjmr18$2ce$2@mamenchi.zrz.TU-Berlin.DE...
> Trent Curry <tcurrey@no.no.no.i.said.no> wrote in comp.lang.perl.misc:
> > "Daniel" <dvdoord@planet.nl> wrote in message
> > news:3f4c7dbf$0$49114$e4fe514c@news.xs4all.nl...
> > > I've a dynamic variable
> > > $var_tmp = "/18";
> > > where the "/18" can also be "/18+100"
> > > I also got a variable
> > > $var_prize = 2000
> > > now the thing is I have to get this
> > > $var_total = 2000/18+100;
> > >
> > > anybody knows how this works ?!?
> >
> >    $var_total = eval($var_tmp);
> > will do what you want.
> >
> > Also, alt.comp.lang.perl & comp.lang.perl are very rare if not virtually
> > extinct news groups. I don't think too many people get them. Though
there
> > seems to be SOME activity in those two said groups...
> >
> > Or is alt.comp.lang.perl just a lesser known group?
>
> alt.comp.lang.perl is a legit alternative to the mainstream Perl groups.
> comp.lang.perl has been decommissioned many years ago -- it *shouldn't*
> exist anywhere, but a sizeable minority of news server still carry it.

Unfortunately, my server carries both :(
Thank you for the info though.




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

Date: 10 Sep 2003 13:39:20 -0700
From: kenny@barmeister.com (Kenny McCarty)
Subject: Re: Converting C++ to Perl
Message-Id: <589a1080.0309101239.2218bdeb@posting.google.com>

"John W. Krahn" <krahnj@acm.org> wrote in message news:<3F5EF329.F46A314F@acm.org>...
> Kenny McCarty wrote:
> > 
> > I am trying to convert this snippet of c++ code to perl and am having
> > some problems getting the results to match up.  I was hoping someone
> > might be able to help me out.  Here is the snippet of C++ code:
> > 
> > DWORD dwVolSerial;
> 
> DWORD is I believe an unsigned long (32 bit) integer.
> 
> 
> > BOOL  bIsRetrieved;
> > char *tmp;
> > char Data[6];
> > // Get the serial number
> > bIsRetrieved =
> >    GetVolumeInformation("C:\\",NULL,NULL,&dwVolSerial,NULL,NULL,NULL,NULL);
> > 
> > // Display the serial number
> > printf("Serial number of drive C is %X\n",dwVolSerial);
> > 
> > tmp = (char*)&dwVolSerial;
> > 
> > Data[0] = tmp[0];
> > Data[1] = tmp[1];
> > Data[2] = tmp[2];
> > 
> > printf("Data is %d-%d-%d\n",Data[0],Data[1],Data[2]);
> > 
> > And here is what I tried in perl:
> > 
> > #just hard coded volume serial number here
> > $str = '303C-6B38';
> > @pieces = split(/-/,$str);
> > @data = split(//,$pieces[0]);
> > printf("Data: %d-%d-%d\n",ord($data[0]),ord($data[1]),ord($data[2]));
> 
> The equivalent perl code is:
> 
> my $str = '303C-6B38';
> my @pieces = map hex, $str =~ /[[:xdigit:]]{2}/g;
> printf "Data: %d-%d-%d\n", @pieces[ 0 .. 2 ];
> 
> 
> > The C++ is run on Windows XP and the perl is run on Free-BSD.  For the
> > perl part I want the user to input the volume serial number of their C
> > drive and I want to create a strign using this data.  I think that the
> > conversions are different between windows and unix and that is where
> > my problem is but I am not sure.  In windows the "3" becomes a "056"
> > but in unix it becomes a "53".  Any help would be apprecieated.
> 
> Are both OSs running on Intel compatible CPUs?  Intel's little-endian
> format means that an integer like 0x12345678 converted to a char array
> will be { 0x78, 0x56, 0x34, 0x12 } so your volume serial number
> '303C-6B38' is really the integer 0x386B3C30.
> 
> 
> 
> John

John,

Thanks so much...you code did the trick.  It just prints out the
numbers in reverse but I can deal with that.  Guess it has to do with
the little-endian/big-endian stuff you said.  I vaguely remember
learning about that in college hehe.  Thanks again for your help  and
everyone else who tried to help too.


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

Date: Wed, 10 Sep 2003 21:46:03 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Counting files
Message-Id: <3F5F9C39.408DC816@earthlink.net>



Tom wrote:

> If your list is from a directory, you can do this to count the number
> of files in each directory:
>
> #!/usr/bin/perl -w
>
> use strict;
> use File::stat;
>
> my %counts;
> countFiles($ARGV[0]);
> foreach my $file(sort keys %counts)
> {
>         print "$file = $counts{$file}\n";
> }
>
> sub countFiles
> {
>         my ($directory) = $_[0];
>         my $fh;
>         if(! opendir $fh,$directory)
>         {
>                 print "Error in accessing $directory.";
>                 return;
>         }
>         while( defined(my $file=readdir($fh)))
>         {
>                 next if $file =~ /^\./;
>                 my $stat = stat("$directory/$file");
>                 if($stat->mode()&040000) { countFiles("$directory/$file") }
>                 else { $counts{"$directory"}++ }
>         }
>         closedir($fh);
> }
>

That is pretty cool.  I'm looking for something like this that will
simply output a list of all files to a text file, maybe along with
some size, date, etc. data.  I could probably do this myself
with this script as a start.  Thanks alot.


Mike




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

Date: 10 Sep 2003 14:35:04 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: Creating a DSN-less connection to a MySQL database
Message-Id: <e0160815.0309101335.369977cb@posting.google.com>

"Al Reynolds" <al@bat400.com> wrote in message news:<bjn7n4$et28p$1@athena.ex.ac.uk>...
> "James Willmore" <jwillmore@cyberia.com> wrote in message
> news:20030909123830.2ce6ab2f.jwillmore@cyberia.com...
> > On Tue, 9 Sep 2003 13:37:09 +0100
> > "Al Reynolds" <al@bat400.com> wrote:
> > > I hope someone will be able to help me with this.
> > >
> > > I am trying to set up a connection to my MySQL
> > > database using perl.  I already have the database
> > > set up and have used it with PHP without any problems.
> > >
> > > When I try and execute the following code, I get an error:
> > > (obviously I have substituted the names/passwords)
> > >
> > > #!/usr/bin/perl
> > > use DBI;
> > > my $dbh =
> > > DBI->connect('DBI:mysql:databasename:localhost','username','passwor
> > > d');$dbh->disconnect or warn "Disconnection error: $DBI::errstr\n";
> > > exit;
> >
> > Try to first, read the documentation for DBD::mysql and second, try to
> > connect using ...
> >
> > DBI->connect('DBI:mysql:database=dbname;host=localhost',
> > 'username',
> > 'password')
> > or die "Connection error: ".$DBI::errstr."\n";
> >
> > If you had read the documentation, you would have discovered that your
> > connection statement is wrong.
> 
> I read enough to decide that the using DBI would
> generate a DSN connection*, which wasn't what I
> wanted, which is why I gave up on the DBI route
> to pursue the ADODB route.  The code I used is
> referred to in several perl-related resources and
> tutorials on different web sites; I doubt that they
> all made the same mistake.  It isn't that uncommon
> for a call to be possible in a variety of forms.
> 
> Anyway, thank you for the code snippet.  If I am
> trying to make a DBI connection again I will use it.
> 
> FWIW, I solved the problem using the older
> mysql.pm module, which is less portable when
> there is a possibility that the database type could
> change later.  It works fine just now though.
> 
> Cheers,
> Al
> 
> 
> * This may be wrong of course - I am still not quite clear
> on the matter.  There is surprisingly little info online about
> the difference between DSN and DSN-less database
> connections and how to set them up using perl.

I had to review the ADODB manual to find out what you meant by
"DSN-less" database.  In general, anything ADODB, DBI can do.  There
is the DBD::ODBC module that you can use to connect to data sources
such as Access.  You can also use DBD::Proxy to create a client/server
type connection.

Basically - this is a term that ADODB authors came up with.  You still
need to declare a data source using a "DSN-less" connection.  So, the
term is mis-leading.

HTH

Jim


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

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.  

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 5479
***************************************


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