[23842] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6045 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 22:32:17 2004

Date: Thu, 29 Jan 2004 19:26:17 -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, 29 Jan 2004     Volume: 10 Number: 6045

Today's topics:
    Re: Search for the new guy (jld8996)
        Seeking advice on memoizing <bik.mido@tiscalinet.it>
    Re: Seeking advice on memoizing ctcgag@hotmail.com
    Re: Seeking advice on memoizing (Anno Siegel)
    Re: Seeking advice on memoizing <bik.mido@tiscalinet.it>
    Re: Seeking advice on memoizing <bik.mido@tiscalinet.it>
        Seen this message? Can't connect to local MySQL server  (Allen Marshall)
    Re: Seen this message? Can't connect to local MySQL ser <noreply@gunnar.cc>
    Re: Serving inline images <robw@sofw.org>
    Re: Serving inline images <tadmc@augustmail.com>
    Re: setting http-referrer using LWP::Simple? (ko)
    Re: Several Perl questions  (Newbie) <spamtrap@dot-app.org>
    Re: Several Perl questions  (Newbie) <edgrsprj@ix.netcom.com>
    Re: Several Perl questions  (Newbie) <spamtrap@dot-app.org>
    Re: Several Perl questions  (Newbie) <edgrsprj@ix.netcom.com>
        Simple opendir(), directory does not exist problem (theo22)
    Re: Simple opendir(), directory does not exist problem (Walter Roberson)
    Re: Simple opendir(), directory does not exist problem <1usa@llenroc.ude>
    Re: Simple opendir(), directory does not exist problem <usenet@morrow.me.uk>
    Re: Simple opendir(), directory does not exist problem <usenet@morrow.me.uk>
    Re: Simple opendir(), directory does not exist problem <tore@aursand.no>
    Re: Simple opendir(), directory does not exist problem <uri@stemsystems.com>
    Re: Simple opendir(), directory does not exist problem <usenet@morrow.me.uk>
    Re: Simple opendir(), directory does not exist problem <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 19 Jan 2004 15:07:07 -0800
From: jld8996@yahoo.com (jld8996)
Subject: Re: Search for the new guy
Message-Id: <103c76d3.0401191507.3e1bf85@posting.google.com>

Many thanks to Bob for his help.  With his help I was able to complete
my script.  Many thanks to Gunnar and Tad for well...nothing.  Thanks
for taking time out of what must be your very busy day to reply to my
message with your criticism.


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

Date: Tue, 27 Jan 2004 15:47:56 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Seeking advice on memoizing
Message-Id: <jduc10pkrh71vddac37q5c5dog1q88se5q@4ax.com>

I'm writing a script to do a few arithmetic computations. The code is
highly factorized in small subs and I'd like to do some "manual"
memoizing, i.e. not using the Memoize module of which I'm aware.

FWIW *one* of the reasons why I do not want to use Memoize is that
values to be cached (1) are not the return values of the subs, (2)
they can be "produced" by different subs.

The data to be saved correspond to couples of integers $a, $b with
$a<$b and the question is: should I store them in a hash indexed, say,
by keys like $a.','.$b or in an AoA? Is there any advantage of one
method over the other?


TIA,
Michele


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

Date: 26 Jan 2004 19:01:45 GMT
From: ctcgag@hotmail.com
Subject: Re: Seeking advice on memoizing
Message-Id: <20040126140145.953$eR@newsreader.com>

Michele Dondi <bik.mido@tiscalinet.it> wrote:
> I'm writing a script to do a few arithmetic computations. The code is
> highly factorized in small subs and I'd like to do some "manual"
> memoizing, i.e. not using the Memoize module of which I'm aware.
>
> FWIW *one* of the reasons why I do not want to use Memoize is that
> values to be cached (1) are not the return values of the subs, (2)
> they can be "produced" by different subs.

So then couldn't they be pulled into a sub sub which is used by the all
the subs?


> The data to be saved correspond to couples of integers $a, $b with
> $a<$b and the question is: should I store them in a hash indexed, say,
> by keys like $a.','.$b or in an AoA? Is there any advantage of one
> method over the other?

What are the legal bounds on $a and $b, and how dense do you expect the
memoized data to get?  If the number that will actually be stored is sparce
WRT the number of legal pairs, that would favor hashes.  If the number
stored is dense WRT all legal pairs, that would favor arrays.

(If you use AoA, it should be $mem[$b][$a], not $mem[$a][$b])

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: 26 Jan 2004 19:25:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Seeking advice on memoizing
Message-Id: <bv3pk0$e8j$1@mamenchi.zrz.TU-Berlin.DE>

 <ctcgag@hotmail.com> wrote in comp.lang.perl.misc:
> Michele Dondi <bik.mido@tiscalinet.it> wrote:
> > I'm writing a script to do a few arithmetic computations. The code is
> > highly factorized in small subs and I'd like to do some "manual"
> > memoizing, i.e. not using the Memoize module of which I'm aware.
> >
> > FWIW *one* of the reasons why I do not want to use Memoize is that
> > values to be cached (1) are not the return values of the subs, (2)
> > they can be "produced" by different subs.
> 
> So then couldn't they be pulled into a sub sub which is used by the all
> the subs?
> 
> 
> > The data to be saved correspond to couples of integers $a, $b with
> > $a<$b and the question is: should I store them in a hash indexed, say,
> > by keys like $a.','.$b or in an AoA? Is there any advantage of one
> > method over the other?
> 
> What are the legal bounds on $a and $b, and how dense do you expect the
> memoized data to get?  If the number that will actually be stored is sparce
> WRT the number of legal pairs, that would favor hashes.  If the number
> stored is dense WRT all legal pairs, that would favor arrays.
> 
> (If you use AoA, it should be $mem[$b][$a], not $mem[$a][$b])

A naive approach would simply use a HoH.  That takes (some) advantage of
sparse data and gives you convenient access (well, as convenient as it
gets).  Think of something else when that approach turns out to be too
simplistic.

A variant of the original hash method might use Perl's simulated multi-
dimensional arrays of yore.  $hash{ $a, $b, ...} is interpreted as
$hash{ join $", $a, $b, ...}.  That puts the necessary join() and split()
of this approach out of the way.

Anno


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

Date: Wed, 28 Jan 2004 09:42:33 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Seeking advice on memoizing
Message-Id: <2ktd10duc81fs8nmi3ecc4191rtotehl6i@4ax.com>

On 26 Jan 2004 19:01:45 GMT, ctcgag@hotmail.com wrote:

>> FWIW *one* of the reasons why I do not want to use Memoize is that
>> values to be cached (1) are not the return values of the subs, (2)
>> they can be "produced" by different subs.
>
>So then couldn't they be pulled into a sub sub which is used by the all
>the subs?

Oh yes, I'm actually using an accessory sub, but data are produced by
(slightly) different means, even though in a consistent way, in
different subs.

>> The data to be saved correspond to couples of integers $a, $b with
>> $a<$b and the question is: should I store them in a hash indexed, say,
>> by keys like $a.','.$b or in an AoA? Is there any advantage of one
>> method over the other?
>
>What are the legal bounds on $a and $b, and how dense do you expect the
>memoized data to get?  If the number that will actually be stored is sparce
>WRT the number of legal pairs, that would favor hashes.  If the number
>stored is dense WRT all legal pairs, that would favor arrays.
>
>(If you use AoA, it should be $mem[$b][$a], not $mem[$a][$b])

I'd say "dense", so I'm favoring the AoA approach. I'll do some tests,
anyway. 

BTW: Would I gain something by preassigning to $#{$mem[$b]}?


Thanks
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Wed, 28 Jan 2004 09:42:34 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Seeking advice on memoizing
Message-Id: <88te1057aqk8fevkoa1inpfqnqul0sr21h@4ax.com>

On 26 Jan 2004 19:25:52 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

>A variant of the original hash method might use Perl's simulated multi-
>dimensional arrays of yore.  $hash{ $a, $b, ...} is interpreted as
>$hash{ join $", $a, $b, ...}.  That puts the necessary join() and split()
>of this approach out of the way.

I knew this feature. Always resisted the temptation to use it because
I've always been told that the Good Thing(TM) is to use "real"
multidimensional hashes, which sounds reasonable, of course.

I think it is a typo you wrote $", though. It is $; in fact!


Thanks,
Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: 24 Jan 2004 14:12:46 -0800
From: arm@camsys.com (Allen Marshall)
Subject: Seen this message? Can't connect to local MySQL server through socket '/tmp/mysql.sock'
Message-Id: <c4b94895.0401241412.aad0701@posting.google.com>

Seen this message? Can't connect to local MySQL server through socket
'/tmp/mysql.sock'

I got this trying to install DBI and DBD for mysql from CPAN.  After
fumbling, a comment by somebody said "Make /tmp world writable and set
the sticky bit"

OK 
so 

chmod uog+t /tmp (and I did +rwx too - was that wrong?)

but no dice, so knowing that mysql has set up its socket in 
/var/lib/mysql/mysql.sock and finding no obvious way to change this
default, I used a soft link

in /tmp

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

and now everything works right.  But, have I compromised file
permissions unnecessarily, or, is there a way to just use
/var/lib/mysql/mysql.sock without this fussing?

Thanks!


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

Date: Sat, 24 Jan 2004 23:55:07 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Seen this message? Can't connect to local MySQL server through socket '/tmp/mysql.sock'
Message-Id: <buutdn$mg87c$1@ID-184292.news.uni-berlin.de>

Allen Marshall wrote:
> Seen this message? Can't connect to local MySQL server through
> socket '/tmp/mysql.sock'

I just saw it in another newsgroup. Don't multi-post!

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Wed, 21 Jan 2004 11:36:55 -0500
From: Robert Wallace <robw@sofw.org>
Subject: Re: Serving inline images
Message-Id: <400EAAA7.B98AC874@sofw.org>

google-google. goo-goo gaa-gaa.

David Jaquay wrote:
> 
> I'm trying to get the following code to work.  I'm using ActiveState
> Perl 5.8.2, Tomcat 4.0.4 under Win2K, and using either Mozilla 1.5 or
> IE 6.  Running this script causes Perl to hang on the next to last
> line, the 'print' line.  (I moved the exit statement around to come to
> this conclusion.)  Running it from the command line appears to work
> just fine, displaying the raw chars from the GIF.
> 
> It would seem from Googling that this is a FAQ, and that binmode is
> the answer, but I've shuffed the binmode lines around to various
> locations, and still get the same results, a hung perl.exe.
> 
> Any ideas as to what's going on?  (And yes, I'm quite new to Perl.)
> 
> Thanks,
> Dave
> 
> print("Content-type:  Image/gif\n\n");
> 
> open(INFILE,'<d:\\sample.gif');
> binmode INFILE;
> undef $/;
> my $img = <INFILE>;
> close(INFILE);
> binmode STDOUT;
> print STDOUT $img;
> exit;


I'm probably not solving anything but, here's my bastardized version:

#!/usr/bin/perl -wT
# url: http://www.example.com/image.cgi

#modules
use CGI qw('param');
use strict;

#variables
my $image =
"/dir1/dir2/dir3/you-get-the-drill/httpd/www/images/arrow01.gif";

# automatic variables
my $thisFileName;
if ($0 =~ /\//){$thisFileName=substr($0,rindex($0,'/')+1,length($0)-1);}
elsif($0 =~
/\\/){$thisFileName=substr($0,rindex($0,'\\')+1,length($0)-1);}


#parsed variables
my $option=param('option');


#directory
if ($option eq "image"){
    image();
} else {
    html();
}

sub html {
    print "content-type: text/html \n\n";
    print "<html><head><title>image</title></head><body>\n";
    print "Inline image test:<br>\n";
    print "<img src=\"$thisFileName?option=image\">\n";
    print "</body></html>\n";
}

sub image {
    print "content-type: image/gif \n\n";
    open(INFILE, $image);
    binmode INFILE;
    undef $/;
    my $img = <INFILE>;
    close(INFILE);
    binmode STDOUT;
    print STDOUT $img;
}

print "anyone have a beef about this?\n";


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

Date: Wed, 21 Jan 2004 11:01:47 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Serving inline images
Message-Id: <slrnc0tc3r.783.tadmc@magna.augustmail.com>

Robert Wallace <robw@sofw.org> wrote:

>     open(INFILE, $image);

>     undef $/;

> print "anyone have a beef about this?\n";


You should always, yes *always*, check the return value from open():

   open(INFILE, $image) or die "could not open '$image'  $!";


This is a much much better way of enabling slurp mode:

   local $/;

or, if you must:

   local $/ = undef;

The value of $/ will go back to "normal" outside of this subroutine's
block. Your code above is changing the global value everywhere.


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


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

Date: 27 Jan 2004 18:59:58 -0800
From: kuujinbo@hotmail.com (ko)
Subject: Re: setting http-referrer using LWP::Simple?
Message-Id: <92d64088.0401271859.550120dd@posting.google.com>

Peder Ydalus <pedery@ifi.uio.no> wrote in message news:<bv62pf$qem$1@maud.ifi.uio.no>...
> Anyone knows if it's possible to set the referrer when I'm using the 
> getstore-function?
> 
> - Peder -

From the LWP::Simple documentation, under the 'DESCRIPTION' heading:

If you need more control or access to the header fields in the
requests sent and responses received, then you should use the full
object-oriented interface provided by the LWP::UserAgent module.

Yes, that means the referer header :)

HTH -keith


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

Date: Mon, 19 Jan 2004 22:32:29 GMT
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Several Perl questions  (Newbie)
Message-Id: <pan.2004.01.19.22.32.29.167767@dot-app.org>

On Mon, 19 Jan 2004 19:32:08 +0000, edgrsprj wrote:

> A plan presently being considered it to create another Web site to which
> people could submit research application Perl (or whatever) program modules
> for storage, downloading, and use by other researchers.

This is an aspect to your question that hasn't yet been addressed. Such an
archive already exists - it's called CPAN (Comprehensive Perl Archive
Network), and it's *huge*.

CPAN provides more than just an archive. There's a module that's included
with Perl that helps manage module installation, by automating the build
process, tracking dependencies so that prerequisites can be automatically
installed, and more.

In short, CPAN represents a huge chunk of infrastructure that you can use
without having to build it yourself.

You can find it at <http://www.cpan.org>

sherm--


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

Date: Mon, 19 Jan 2004 22:49:27 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Re: Several Perl questions  (Newbie)
Message-Id: <X9ZOb.15640$i4.6436@newsread1.news.atl.earthlink.net>

January 19, 2004



Thanks.  This proposed Web site would also contain research reports etc. and
probably some operational CGI programs.  However that Cpan site looks
interesting.  It might serve as a good central location to store new Perl
modules.  They would be doing things such as generating data regarding the
positions of the sun and the moon in the sky for different times.  I aleady
have Fortran subroutine codes for the initial modules but want to get them
into a language that everyone can use.




"Sherm Pendley" <spamtrap@dot-app.org> wrote in message
news:pan.2004.01.19.22.32.29.167767@dot-app.org...
> On Mon, 19 Jan 2004 19:32:08 +0000, edgrsprj wrote:
>

> You can find it at <http://www.cpan.org>
>
> sherm--




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

Date: Mon, 19 Jan 2004 23:31:46 GMT
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Several Perl questions  (Newbie)
Message-Id: <pan.2004.01.19.23.31.46.199237@dot-app.org>

On Mon, 19 Jan 2004 22:49:27 +0000, edgrsprj wrote:

> They would be doing things such as generating data regarding the
> positions of the sun and the moon in the sky for different times.  I aleady
> have Fortran subroutine codes for the initial modules but want to get them
> into a language that everyone can use.

Just to illustrate the usefulness of CPAN - If, by "Fortran subroutine
codes," you're referring to SLAlib, there's already a Perl interface to it:

<http://theoryx5.uwinnipeg.ca/CPAN/data/Astro-SLA/SLA.html>

:-)

sherm--


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

Date: Tue, 20 Jan 2004 00:11:06 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Re: Several Perl questions  (Newbie)
Message-Id: <um_Ob.15696$i4.3501@newsread1.news.atl.earthlink.net>

January 19, 2004

I will have to take a more detailed look at those routines.  I was planning
to use the ones available at the following Web site.

http://aa.usno.navy.mil/software/novas/novas_info.html



But if the necessary routines are already available in Perl at some other
location then that might save a lot of programming time.


"Sherm Pendley" <spamtrap@dot-app.org> wrote in message
news:pan.2004.01.19.23.31.46.199237@dot-app.org...
> On Mon, 19 Jan 2004 22:49:27 +0000, edgrsprj wrote:
>
> > They would be doing things such as generating data regarding the
> > positions of the sun and the moon in the sky for different times.  I
aleady
> > have Fortran subroutine codes for the initial modules but want to get
them
> > into a language that everyone can use.
>
> Just to illustrate the usefulness of CPAN - If, by "Fortran subroutine
> codes," you're referring to SLAlib, there's already a Perl interface to
it:
>
> <http://theoryx5.uwinnipeg.ca/CPAN/data/Astro-SLA/SLA.html>
>
> :-)
>
> sherm--




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

Date: 19 Jan 2004 14:59:57 -0800
From: theo_22@yahoo.com (theo22)
Subject: Simple opendir(), directory does not exist problem
Message-Id: <6f1e0d54.0401191459.1cfc7a35@posting.google.com>

Newbie question:
Windows 2000, Perl v5.8.0 built for MSWin32-x86-multi-thread

All I want to do is pass an argument to my script on the command line.
The argument is the directory that gets passed to the opendir()
function.  When I run the script , I always get an error:
Uncaught exception from user code:
        Directory D:\My Documents\ScriptTesting does not exist: No
directory at D:\My Documents\ScriptTesting\GetDirList3.pl line 12.

How can it say the directory does not exist if the file that it is
referring to with the error, is in that directory?  If I hard code the
directory in the opendir() function, it works fine.

Here is my code.  You will notice it takes a directory and then spits
it out to a .txt file.  It works great except I can't pass the
directory I want it to list through the command line:
******************************************
#!/usr/bin/perl -w

use strict;
use diagnostics;

#Tried a variable name for ARGV[0] and chomp as alternative, but it
made no difference so I commented it all out.
#my $DirPath=$ARGV[0];
#chomp($DirPath);

#Create directory handle so we can get a list of all the files in the
directory.
#opendir(MyDir, '$DirPath') || die "Directory $DirPath does not exist:
$!";
opendir(MyDir, '$ARGV[0]') || die "Directory $ARGV[0] does not exist:
$!";

#Create filehandle to dump list of directory files into a .txt file
for reading.
open(MyFile, ">My_Files.txt") || die "Cannot open My_Files.txt: $!";

#Gets the list of only .txt files
my @Files = grep (/\.txt$/, readdir MyDir);

#Print each file in the directory to a .txt file.  Prepend filenames
with thier full path.
foreach my $Files (@Files){
	$Files = "$ARGV[0]\\$Files";
	print MyFile "$Files\n";
}

print "My_Files.txt file created with list of all .txt files!\n";

#Close directory and file handles.
closedir(MyDir);
close(MyFile);
****************************************

Please Help.  Here is the command that I used:
C:>GetDirList3.pl "D:\My Documents\ScriptTesting" 

What am I doing wrong here?

Thx!!


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

Date: 19 Jan 2004 23:10:29 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Simple opendir(), directory does not exist problem
Message-Id: <buho55$fst$1@canopus.cc.umanitoba.ca>

In article <6f1e0d54.0401191459.1cfc7a35@posting.google.com>,
theo22 <theo_22@yahoo.com> wrote:
:Windows 2000, Perl v5.8.0 built for MSWin32-x86-multi-thread

:The argument is the directory that gets passed to the opendir()
:function.  When I run the script , I always get an error:
:Uncaught exception from user code:
:        Directory D:\My Documents\ScriptTesting does not exist: No
:directory at D:\My Documents\ScriptTesting\GetDirList3.pl line 12.

:opendir(MyDir, '$ARGV[0]') || die "Directory $ARGV[0] does not exist:
:$!";

Single-quotes don't interpolate, but double-quotes do. So you
are trying to open a directory literally named  $ARGV[0]  and
then complaining with a message that uses the -contents- of $ARGV[0]

I suggest you just remove the single-quotes.

If you choose to double-quote instead, then keep in mind that
inside double-quotes, the backslashes in the string you provide
are going to be interpreted as escape sequences. To use double-quotes
you would have to quote-meta or use  "\Q$ARGV[0]\E"
-- 
Disobey all self-referential sentences!


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

Date: 19 Jan 2004 23:11:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Simple opendir(), directory does not exist problem
Message-Id: <Xns9475B8FEF8A17asu1cornelledu@132.236.56.8>

theo_22@yahoo.com (theo22) wrote in news:6f1e0d54.0401191459.1cfc7a35
@posting.google.com:

 
> Please Help.  Here is the command that I used:
> C:>GetDirList3.pl "D:\My Documents\ScriptTesting" 
> 
> What am I doing wrong here?

I did not look at the rest of your script, but you might want to try the 
following alternatives:

C:>GetDirList3.pl "D:/My Documents/ScriptTesting" 

or 

C:>GetDirList3.pl "D:\\My Documents\\ScriptTesting" 

Sinan.

-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: Mon, 19 Jan 2004 23:15:47 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Simple opendir(), directory does not exist problem
Message-Id: <buhof3$ok4$1@wisteria.csv.warwick.ac.uk>


theo_22@yahoo.com (theo22) wrote:
> opendir(MyDir, '$ARGV[0]') || die "Directory $ARGV[0] does not exist:
> $!";

This attempts to open a directory called $ARGV[0]. The double-quotes
used for the die message interpolate the variable, those single quotes
don't. You don't need to quote it at all; also, it is more usual to
use uppercase for IO handles:

opendir my $DIR, $ARGV[0] or die "Cannot open $ARGV[0]: $!";

Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
ben@morrow.me.uk |----------------+---------------| The Levellers, 'Believers'


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

Date: Mon, 19 Jan 2004 23:17:53 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Simple opendir(), directory does not exist problem
Message-Id: <buhoj1$ok4$2@wisteria.csv.warwick.ac.uk>


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
> If you choose to double-quote instead, then keep in mind that
> inside double-quotes, the backslashes in the string you provide
> are going to be interpreted as escape sequences. To use double-quotes
> you would have to quote-meta or use  "\Q$ARGV[0]\E"

Bzzzt! Wrong.

A double quoted string != a regex.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: Tue, 20 Jan 2004 00:24:30 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Simple opendir(), directory does not exist problem
Message-Id: <pan.2004.01.19.23.24.08.499878@aursand.no>

On Mon, 19 Jan 2004 14:59:57 -0800, theo22 wrote:
> #opendir(MyDir, '$DirPath') || die "Directory $DirPath does not exist:
> $!";
> opendir(MyDir, '$ARGV[0]') || die "Directory $ARGV[0] does not exist:
> $!";

You need double quotes when dealing with variables, or - in this case - no
quotes at all;

  opendir(MYDIR, $DirPath) or die "$!\n";
  opendir(MYDIR, $ARGV[0]) or die "$!\n";

Try this script to see the difference;

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

  my $variable = 'test';
  print '$variable' . "\n";
  print "$variable" . "\n";
  print  $variable  . "\n";


-- 
Tore Aursand <tore@aursand.no>
"To cease smoking is the easiset thing I ever did. I ought to know,
 I've done it a thousand times." -- Mark Twain


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

Date: Mon, 19 Jan 2004 23:54:04 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Simple opendir(), directory does not exist problem
Message-Id: <x7smibjy04.fsf@mail.sysarch.com>

>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:

  BM> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
  >> If you choose to double-quote instead, then keep in mind that
  >> inside double-quotes, the backslashes in the string you provide
  >> are going to be interpreted as escape sequences. To use double-quotes
  >> you would have to quote-meta or use  "\Q$ARGV[0]\E"

  BM> Bzzzt! Wrong.

  BM> A double quoted string != a regex.

bzzzt! escape sequences exist in double quotish strings too. what do you
call \n, \r, \t, etc?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Mon, 19 Jan 2004 23:59:33 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Simple opendir(), directory does not exist problem
Message-Id: <buhr15$q4i$1@wisteria.csv.warwick.ac.uk>


Uri Guttman <uri@stemsystems.com> wrote:
> >>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:
> 
>   BM> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
>   >> If you choose to double-quote instead, then keep in mind that
>   >> inside double-quotes, the backslashes in the string you provide
>   >> are going to be interpreted as escape sequences. To use double-quotes
>   >> you would have to quote-meta or use  "\Q$ARGV[0]\E"
> 
>   BM> Bzzzt! Wrong.
> 
>   BM> A double quoted string != a regex.
> 
> bzzzt! escape sequences exist in double quotish strings too. what do you
> call \n, \r, \t, etc?

Yes, of course. However,

my $x = '\n\r\t';
my $y = "$x";

will not (as Walter suggested) give a string with any control
characters in it. \Q$var\E *is* useful in regexen, as those escape
sequences which are regexish rather than double-quoteish will be
interpreted even if they came in from a variable.

Ben

-- 
               EAT
               KIDS                                          (...er, whoops...)
               FOR                                             ben@morrow.me.uk
               99p


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

Date: Tue, 20 Jan 2004 00:04:20 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Simple opendir(), directory does not exist problem
Message-Id: <x7hdyrjxiz.fsf@mail.sysarch.com>

>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:

  BM> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
  >> >> If you choose to double-quote instead, then keep in mind that
  >> >> inside double-quotes, the backslashes in the string you provide
  >> >> are going to be interpreted as escape sequences. To use double-quotes
  >> >> you would have to quote-meta or use  "\Q$ARGV[0]\E"

  BM> my $x = '\n\r\t';
  BM> my $y = "$x";

  BM> will not (as Walter suggested) give a string with any control
  BM> characters in it. \Q$var\E *is* useful in regexen, as those escape
  BM> sequences which are regexish rather than double-quoteish will be
  BM> interpreted even if they came in from a variable.

i agree walter said the wrong thing there. data is never interpolated,
only literal \ and $ and such.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

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


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