[15542] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2958 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 5 12:16:42 2000

Date: Fri, 5 May 2000 06:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <957532214-v9-i2958@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 5 May 2000     Volume: 9 Number: 2958

Today's topics:
    Re: problem with "system" and file copy <morbus@disobey.com>
    Re: re-initializing through each loop nobull@mail.com
    Re: Regex for not matching a particular string nobull@mail.com
        Saving a hash to a file gawith1501@my-deja.com
    Re: Saving a hash to a file <sb@muccpu1.muc.sdm.de>
        Stored Cookie <stephane@siw.ch>
    Re: Stored Cookie (Tony L. Svanstrom)
    Re: Stored Cookie <bill.kemp@wire2.com>
        System call window with win32 <dfernandez@uf-isf.es>
    Re: Text output (Bart Lateur)
        To make the difference between file and directory defaultuser@domain.com
    Re: To make the difference between file and directory nobull@mail.com
    Re: To make the difference between file and directory <billy@arnis-bsl.com>
    Re: To make the difference between file and directory <andersen+@rchland.ibm.com>
        Trim A String To 16 Characters <skpurcell@hotmail.com>
        unlink ( deleting file) not working robbie_pa@my-deja.com
    Re: unlink ( deleting file) not working nobull@mail.com
    Re: Using signals under Win NT - Active Perl (Clinton A. Pierce)
    Re: Validating URLs (Bart Lateur)
    Re: while(<@array>) (was: How to find a matching ")"?) <rhomberg@ife.ee.ethz.ch>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 05 May 2000 07:12:19 -0400
From: Morbus Iff <morbus@disobey.com>
Subject: Re: problem with "system" and file copy
Message-Id: <morbus-41FE5E.07121905052000@news.totalnetnh.net>

In article <391159cd.108765115@news.icn.siemens.de>, 
andreas.boerner@icn.siemens.de wrote:

> $command = "cp ~/dir1/*.c ~dir2";
> print $command;
> $rc = system($command);
> print "rc=$rc\n";

When executing commands on the system, you must use backticks instead of 
quotes:

   $command = `cp ~/dir1/*.c ~dir2";

Generally, the rule is:

   quotes ("") = variable interpolation
   singles ('') = no interpolation
   backticks (``) = system exec

Such that these are all different:

   $command = "cp $directory1 $directory2";
   $command = 'cp $directory1 $directory1";
   $command = `cp $directory1 $directory1";

-- 
Morbus Iff
http://www.disobey.com/


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

Date: 05 May 2000 12:18:09 +0100
From: nobull@mail.com
Subject: Re: re-initializing through each loop
Message-Id: <u9wvl96ya6.fsf@wcl-l.bham.ac.uk>

"Jonah" <nomail@nomail.com> writes:

> Is there anything wrong with re-intializing a variable
> through each loop.

No, it is generally (although as is the way with these things, not
universally) agreed that variables should be limited to the smallest
possible scope/lifetime.  This is not specifically a matter of Perl
style it's good practice in all languages.

> What's happening behind the scenes in either case, in terms
> of the allocation of $var using my?

I do not know nor care exactly how the Perl compiler and bytecode
interpreter implement my() variables.  All I (as a Perl programmer)
care about is how they look to me.

> From what I understand, the variable gets created, then destroyed, then
> created,

Yes, and I would expect there is a small cost in CPU cycles associated
with doing this.  However, unless the loop is truely trivial, this
will be tiny compared to the CPU cycles spent doing the real task.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 05 May 2000 12:31:32 +0100
From: nobull@mail.com
Subject: Re: Regex for not matching a particular string
Message-Id: <u9u2gd6xnv.fsf@wcl-l.bham.ac.uk>

nobull@mail.com writes:

> /abc/ && $' !~ /def/ 

That is pathologically bad advice please see "perldoc perlvar" for
why.

BTW: For giving such moronic advice why have I not been flamed,
publicly flogged or worse still likened to Godzilla?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 05 May 2000 10:02:10 GMT
From: gawith1501@my-deja.com
Subject: Saving a hash to a file
Message-Id: <8eu66t$d9v$1@nnrp1.deja.com>

Hello everybody!

Can anyone tell me how to save a hash to a file. Yes, I know, DB_File is the
best choice, but DB_File does not support nested hashes, and that´s what I
need.

So long.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 5 May 2000 10:12:04 GMT
From: Steffen Beyer <sb@muccpu1.muc.sdm.de>
Subject: Re: Saving a hash to a file
Message-Id: <8eu6pk$jv8$1@solti3.sdm.de>

In article <8eu66t$d9v$1@nnrp1.deja.com>, gawith1501@my-deja.com wrote:

> Can anyone tell me how to save a hash to a file. Yes, I know, DB_File is the
> best choice, but DB_File does not support nested hashes, and that´s what I
> need.

CPAN: Data::Dumper, FreezeThaw, Storable

-- 
    Steffen Beyer <sb@engelschall.com>
    http://www.engelschall.com/u/sb/whoami/ (Who am I)
    http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
    http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)


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

Date: Fri, 05 May 2000 11:59:38 GMT
From: "Chello" <stephane@siw.ch>
Subject: Stored Cookie
Message-Id: <KIyQ4.81264$6X3.1960463@news.chello.at>

I'm looking to create stored cookie. In fact I need a cookie who is stored
on th HD. How can I do it? Do somebody have a code example?

Thanks in advance


Stéphane




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

Date: Fri, 5 May 2000 14:19:08 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Stored Cookie
Message-Id: <1ea5x24.1v3ousl1wgz6qoN%tony@svanstrom.com>

Chello <stephane@siw.ch> wrote:

> I'm looking to create stored cookie. In fact I need a cookie who is stored
> on th HD. How can I do it? Do somebody have a code example?

A second x-post just 3 hours after asking the same question... Sorry,
you screwed it up for yourself, now you won't get any serious replies
from the people you really want to reply to your questions...


     /Tony
-- 
     /\___/\ Who would you like to read your messages today? /\___/\
     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
 --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
 DSS: 0x9363F1DB, Fp: 6EA2 618F 6D21 91D3 2D82  78A6 647F F247 9363 F1DB
 ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
    \O/   \O/  ©1999  <http://www.svanstrom.com/?ref=news>  \O/   \O/


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

Date: Fri, 5 May 2000 13:24:17 +0100
From: "W Kemp" <bill.kemp@wire2.com>
Subject: Re: Stored Cookie
Message-Id: <957529537.11610.0.nnrp-09.c3ad6973@news.demon.co.uk>


Tony L. Svanstrom wrote in message
<1ea5x24.1v3ousl1wgz6qoN%tony@svanstrom.com>...
>Chello <stephane@siw.ch> wrote:
>
>> I'm looking to create stored cookie. In fact I need a cookie who is
stored
>> on th HD. How can I do it? Do somebody have a code example?
>

>A second x-post just 3 hours after asking the same question... Sorry,
>you screwed it up for yourself, now you won't get any serious replies
>from the people you really want to reply to your questions...


Is this carte blanche to be silly then?

Don't store cookies on the HD it is potentially very damaging.  People will
steal the chocolate chips, and the crumbs and nuts can get caught in the
bearings, causing premature wear and HD failiure.




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

Date: Fri, 5 May 2000 13:08:47 +0200
From: "Diego Fernández" <dfernandez@uf-isf.es>
Subject: System call window with win32
Message-Id: <8eua51$dfd$1@talia.mad.ttd.net>

Hello.

My problem is that when I execute a system call in my perl script, Windows
create a black text window, that disapear when the command finishes.

This is awfull when the perl is a cgi, because the web server is all the
time opening and closing windows.

¿Is there any way to avoid this?

Thanks




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

Date: Fri, 05 May 2000 12:53:33 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Text output
Message-Id: <3916c415.4094658@news.skynet.be>

Amri, Kuross [WOLL:4009-I:EXCH] wrote:

>	I have a text file that has a formatted out put. It is some tables.
>When I created the link to display the text file it sends out a 500
>error. In the server logs it complains about unable to exec format. 
>	Does enybody know what is happening or what I can do about it?

Is this a script? Is the "#!" line pointing to the Perl executable? And,
er, is this the Zeus server? Just curious. :-)

-- 
	Bart.


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

Date: Fri, 05 May 2000 13:25:51 +0200
From: defaultuser@domain.com
Subject: To make the difference between file and directory
Message-Id: <3912AFBF.D70FDB8F@domain.com>

I think it's a simple suestion, i'ld like to make the display a
directories and files tree and I need for that to parse a directory (I
use readdir) but what is the best way in Perl to make the difference
between a file and a directory.

Thanks



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

Date: 05 May 2000 13:01:42 +0100
From: nobull@mail.com
Subject: Re: To make the difference between file and directory
Message-Id: <u9n1m56w9l.fsf@wcl-l.bham.ac.uk>

defaultuser@domain.com writes:

> I think it's a simple suestion, i'ld like to make the display a
> directories and files tree and I need for that to parse a directory (I
> use readdir)

Consider using File::Find it may be better (depending on context).

> but what is the best way in Perl to make the difference
> between a file and a directory.

The -d operator.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 05 May 2000 12:29:51 GMT
From: Ilja <billy@arnis-bsl.com>
Subject: Re: To make the difference between file and directory
Message-Id: <8euerh$m8p$1@nnrp1.deja.com>

In article <3912AFBF.D70FDB8F@domain.com>,
  defaultuser@domain.com wrote:
> I think it's a simple suestion, i'ld like to make the display a
> directories and files tree and I need for that to parse a directory (I
> use readdir) but what is the best way in Perl to make the difference
> between a file and a directory.
>

Consult 'perldoc perlfunc' manual, the section "-X filetest operators".

Also note, that readdir() will give you filenames only
(not full paths to files), so to use -X operators
on a file you should either:

1. Construct a full path (concatenating directory name and file name);

2. or your 'current directory' should be one you have readdir'ed
the filename from.

Good luck.

Ilja.




Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 05 May 2000 07:49:30 -0500
From: "Paul R. Andersen" <andersen+@rchland.ibm.com>
Subject: Re: To make the difference between file and directory
Message-Id: <3912C35A.16BA5A5F@rchland.ibm.com>


--------------5C83D022969BD5CABE75B03F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Check out -f and -d in your perl book (page 85 in the camel book).  Then
go read about grep.

Paul

defaultuser@domain.com wrote:

> I think it's a simple suestion, i'ld like to make the display a
> directories and files tree and I need for that to parse a directory (I
> use readdir) but what is the best way in Perl to make the difference
> between a file and a directory.
>
> Thanks

--
Paul Andersen
-- I can please only ONE person per day.
-- Today is NOT your day.
-- Tomorrow isn't looking good either.



--------------5C83D022969BD5CABE75B03F
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Check out -f and -d in your perl book (page 85 in the camel book).&nbsp;
Then go read about grep.
<p>Paul
<p>defaultuser@domain.com wrote:
<blockquote TYPE=CITE>I think it's a simple suestion, i'ld like to make
the display a
<br>directories and files tree and I need for that to parse a directory
(I
<br>use readdir) but what is the best way in Perl to make the difference
<br>between a file and a directory.
<p>Thanks</blockquote>

<pre>--&nbsp;
Paul Andersen
-- I can please only ONE person per day.
-- Today is NOT your day.
-- Tomorrow isn't looking good either.</pre>
&nbsp;</html>

--------------5C83D022969BD5CABE75B03F--



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

Date: Fri, 5 May 2000 07:47:50 -0500
From: "spurcell" <skpurcell@hotmail.com>
Subject: Trim A String To 16 Characters
Message-Id: <3912c2d9$0$11849@wodc7nh1.news.uu.net>

Hello,
I had a request to take a bunch of strings and truncate (cut off) the string
at 16 characters. In the Camel, there is a section about splitting into
substrings, p220-222, but I don't know if that is the answer. (doesn't look
right to me).  I could also do a reg exp, but I want to build it correctly,
and do it right.

Could someone direct me to the proper documentation for this topic?

Thanks
Scott




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

Date: Fri, 05 May 2000 11:50:21 GMT
From: robbie_pa@my-deja.com
Subject: unlink ( deleting file) not working
Message-Id: <8euchp$jq8$1@nnrp1.deja.com>

Hi!
I am trying to delete files older than 2 days in a directory NT4 NTFS

#!c:/perl/bin/perl.exe
use Win32::File;
$cat = "c:/windows/dist";

#checking if the dir exists
opendir(KAT, $cat) || die "can't opendir $cat: $!";

#readdir reads everything into @katalog except . & ..
@katalog = grep { /[^\.+]/ } readdir (KAT);
closedir (KAT);
foreach $fil (@katalog) {
	chomp ($fil);
#checking if fil is older than 2 days
	if(-M $fil > 2) {
#deleting fil if older than 2 days
		unlink ($fil);
	};
}


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 05 May 2000 13:22:34 +0100
From: nobull@mail.com
Subject: Re: unlink ( deleting file) not working
Message-Id: <u9ln1p6vat.fsf@wcl-l.bham.ac.uk>

robbie_pa@my-deja.com writes:

> Hi!
> I am trying to delete files older than 2 days in a directory NT4 NTFS
> 
> #!c:/perl/bin/perl.exe
> use Win32::File;
> $cat = "c:/windows/dist";
> 
> #checking if the dir exists
> opendir(KAT, $cat) || die "can't opendir $cat: $!";
> 
> #readdir reads everything into @katalog except . & ..
> @katalog = grep { /[^\.+]/ } readdir (KAT);

Actually reads everything into @katalog except . & .. and ... and
 ..... and .+..+. and ++++ so on. (i.e. any file whose name is not
entirely made up of periods and plus signs).

> closedir (KAT);
> foreach $fil (@katalog) {
> 	chomp ($fil);

Redundant, readdir() does not append EOL characters.

> #checking if fil is older than 2 days
> 	if(-M $fil > 2) {
> #deleting fil if older than 2 days
> 		unlink ($fil);

Should be:

  unlink("$cat/$fil") || dir "Unlink $fil: $!";

Or, arguably better:

  use File::Spec;
  unlink(File::Spec->catfile($cat,$fil)) ||
    dir "Unlink $fil: $!";

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 05 May 2000 02:19:07 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Using signals under Win NT - Active Perl
Message-Id: <vcqQ4.59798$h01.435656@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <3911AA9E.7D8CF072@ll.mit.edu>,
	Stephen Dodd <dodd@ll.mit.edu> writes:
> 
> I've tried handling the INT and ALRM signals and have been unsuccessful.
> I also get an "unimplement function alarm" in the following script-

Sadly, signals are MIA from Perl under Win32.  This has caused me no 
end of grief.  Patches welcome, although from what I'm told: this 
lameness cannot be fixed.

-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours! 
  clintp@geeksalad.org         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Fri, 05 May 2000 12:49:25 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Validating URLs
Message-Id: <3914c30c.3830030@news.skynet.be>

David Allen wrote:

>> is there a way to connect to these from a PERL script and check for a
>> return code such as a 404 ?
>
>Yes - and it's pretty easy.  The quickest way to grab a URL:
>
>use LWP::Simple;
>
>print get('http://www.foobar.com/somefile.html');

If you use getstore(), the contents is put in a file, and the return
value is the numeric status code, such as "200" (OK).

I've not tried head() just yet...

-- 
	Bart.


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

Date: Fri, 05 May 2000 14:46:22 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: while(<@array>) (was: How to find a matching ")"?)
Message-Id: <3912C29E.1565CE7E@ife.ee.ethz.ch>

nobull@mail.com wrote:

> Only if the stuff inside is a bareword or a simple scalar variable.
> Otherwise <...> is glob().  See "perldoc perlop".
> 
> > while (<@the_names>)
> >
> > Works without error messages in the instances I've used it.
> 
> See "perldoc perlop" and you can infer that this is interpreted as:
> 
> while (defined($_=glob("@the_names")))

That's it. Things start to get funny if @the_names contains special
shell characters. Like '*' or ' & rm -rf ~' etc.

- Alex


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 2958
**************************************


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