[26274] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8456 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 26 06:05:35 2005

Date: Mon, 26 Sep 2005 03:05:05 -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           Mon, 26 Sep 2005     Volume: 10 Number: 8456

Today's topics:
    Re: complete manual and reference <joe@inwap.com>
    Re: FAQ 4.42 How can I tell whether a certain element i <segraves_f13@mindspring.com>
        How do I get more-detailed directory info? <bogus.address@no.spam.com>
        print  @{1} versus print  @{11} <fishfry@your-mailbox.com>
    Re: print  @{1} versus print  @{11} <tassilo.von.parseval@rwth-aachen.de>
    Re: Script for migrating HTML tree into a single direct <panam@nospam.com>
    Re: script to run the program <joe@inwap.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 25 Sep 2005 23:59:23 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: complete manual and reference
Message-Id: <VJmdnfSJ-v_QAareRVn-tg@comcast.com>

nobody wrote:
> where can i get a complete manual and a complete reference for understanding
> perl language?

Start -> Programs -> ActivePerl -> Documentation
has the same info as
http://aspn.activestate.com/ASPN/Perl/Reference/

In other words, install perl on your computer and you will have
the documentation on your hard drive.
	-Joe


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

Date: Mon, 26 Sep 2005 02:07:47 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
Message-Id: <TJIZe.4215$QE1.770@newsread2.news.atl.earthlink.net>

<axel@white-eagle.invalid.uk> wrote in message
news:v6DZe.7097$fl6.6646@fe2.news.blueyonder.co.uk...
> Bill Segraves <segraves_f13@mindspring.com> wrote:
> > "John Bokma" <john@castleamber.com> wrote in message
>
> >> Write? Does it have to be in Perl? There is plenty of Wiki software
etc.
> >> out there, probably not written in Perl, but I don't care about that.
The
> >> OS I use is not written in Perl either :-)
>
> > OTOH, there is at least one that *is* written in Perl, e.g.,
>
> > http://c2.com/cgi/wiki?QuickiWiki
> > http://c2.com/cgi/wiki?ClusterWiki
> > http://www.wiki.org/
>
> >> So what are the next steps to have a Perl wiki? Especially for the FAQ
> >> part?
>
> > 1. Download and install QuickiWiki.
> > 2. Write a script to extract Usenet clpm postings from the PerlFAQ
server
> > into Wiki format.
>

Somehow the smiley face I put with my suggestion was dropped. Sorry you
missed the subtle point, e.g.,

"Please let us know when you have it up and running, John. ;-)"

OTOH, I may have misread the context of John's remarks, thinking the issue
was about *if* a Perl FAQ *could* be implemented as a Wiki, rather that *if*
such a Perl FAQ *should* be implemented. I was already aware that a well
established process for ongoing development of the Perl FAQ is already in
place, e.g., see http://faq.perl.org/.

> And then decide both on a political and technical level how and when the
> actual FAQ would be updated; or *if* changes would be fed back in or
should
> the Wiki version would just develop separately as an additional resource.
>
> Axel
>

Quite so, Axel. I was just trying to answer the questions posed by John
Bokma. Whether such a FAQ *should* be done is another issue, as you have
stated.

The only issue I have with your statement is that the phrase "And then"
should be replaced with "First,".

Cheers.

--
Bill Segraves








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

Date: Mon, 26 Sep 2005 09:47:13 GMT
From: "Robbie Hatley" <bogus.address@no.spam.com>
Subject: How do I get more-detailed directory info?
Message-Id: <BsPZe.406$Y_5.123@newssvr11.news.prodigy.com>

Greetings, group.  This is the first time I've posted here,
or in any Perl-related forum for that matter.  I'm a rank
beginner at Perl.  I'm trying to teaching myself the language
from reading books (incl. one with a camel on the cover, and
one with a llama; not that anyone here would recongize those,
of course), trying my own Perl hacks, and struggling
with compiler errror messages.

The training program I'm currently trying to write is a
duplicate-file finding/removing program.  A rather elaborate
program when written in C++.  An engineer friend told me it
would be much simpler in Perl.  I had to tell him, "Cool, but
I don't know Perl".  He seemed offended and said "Your loss.".

So... pasted below is my first (incomplete) attempt at writing
a real Perl program.

I have hundreds of questions about Perl, but for now I'll
ask this group just two questions:

1:
How do I get a more-detailed directory listing than is offered
by the readdir function?  Is their any way to goad that
function into coughing-up file-type (file or directory or link),
size in bytes, mod-time, mod-date, attribtutes, etc.?  Or do I
have to use some other approach to get that data?

2:
Is there a better way to emulate the C++ concept of a "list of
structs" than what I'm doing below?  (I'm using an array of refs
to hashes.)



Here's my program at it's current state of development:



################################################################################
##########
# dedup3.perl
# Duplicate file finding/erasing program.
# Written by Robbie Hatley, as a "learn Perl" excercise.
# Plan: Recursively decend directory tree starting from current working
directory,
# and make a master list of all files encountered on this branch.  Order the
list by size.
# Within each size group, compare each file, from left to right, to all the
files to
# its right.  If a duplicate pair is found, alert user and get user input.  Give
user
# these choices:
# 1. Erase left file
# 2. Erase right file
# 3. Ignore this pair of duplicate files and move to next
# 4. Quit
# If user elects to delete a file, delete it, then move to next duplicate file
pair.
################################################################################
##########

use strict;
use warnings;

use Cwd;

# Not valid Perl; how do I do this???
# struct FileRecord
# {
#    std::string         Date;
#    std::string         Time;
#    std::string         Type;
#    long int            Size;
#    std::string         Attr;
#    std::string         Name;
# };
#
# std::list<rhdir::FileRecord> FileList;
#
# TODO: How do I extract size, mod-time, mod-date, type (file or dir),
# attributes, etc. and store in an array of structs (or Perl equiv)???
#
# Try an array of hashes?

my $CurDir = getcwd();
print "CWD = ", $CurDir, "\n";
opendir(Dot, ".") or die "Can\'t open the directory!!!";

my @LocalFiles;
my $FileName;
my $FileRecord;

while ($FileName=readdir(Dot))
{
   $FileRecord=
      {
         "Date" => "Unknown",
         "Time" => "Unknown",
         "Type" => "Unknown",
         "Size" => 42,
         "Attr" => "Unknown",
         "Name" => $FileName
      };
   push @LocalFiles, $FileRecord;
}

closedir(Dot);

foreach $FileRecord (@LocalFiles)
{
   print($$FileRecord{"Name"}, "\n");
}




-- 
Cheers,
Robbie Hatley
Tustin, CA, USA
email: lonewolfintj at pacbell dot net
web:   home dot pacbell dot net slant earnur slant




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

Date: Sun, 25 Sep 2005 21:53:32 -0700
From: fishfry <fishfry@your-mailbox.com>
Subject: print  @{1} versus print  @{11}
Message-Id: <fishfry-3FCA59.21533225092005@comcast.dca.giganews.com>

Can someone please explain this result?

print @{1}

compiles but doesn't print anything.

@{11}

throws "Can't use string ("11") as an ARRAY ref while "strict refs" in 
use"

This one's really got me going. Perl 5.8.7.


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

Date: Mon, 26 Sep 2005 09:13:24 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: print  @{1} versus print  @{11}
Message-Id: <slrndjf7sk.ra.tassilo.von.parseval@localhost.localdomain>

Also sprach fishfry:

> Can someone please explain this result?
>
> print @{1}
>
> compiles but doesn't print anything.
>
> @{11}
>
> throws "Can't use string ("11") as an ARRAY ref while "strict refs" in 
> use"
>
> This one's really got me going. Perl 5.8.7.

This is a bit obscure and probably due to the special nature of the
digit variables ($1, $2...). You get an idea when you use B::Deparse to
see that for perl those two things are treated differently in a subtle
manner:

    ethan@ethan:~$ perl -MO=Deparse -e 'print @{1}'
    print @1;
    -e syntax OK
    ethan@ethan:~$ perl -MO=Deparse -e 'print @{11}'
    print @{11;};
    -e syntax OK

@{1} is condensed into @1. Strictures don't warn on certain symbols that
are always global and live in package main::. These are variables with
digits and punctuation as name (so you are always allowed to use e.g.
$`, @`, %` etc., even $²).

@{11} however is @{11;} which is a symbolic reference. That means the
block {...} is executed and whatever is returned is turned into a string
and taken as the name of the variable. These (also called soft
references) are disallowed when "strict 'refs'" are in effect.

Having said that, this different treatment of @{1} and @{11} is a bug
IMO.

Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


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

Date: Mon, 26 Sep 2005 09:13:12 +0200
From: Pan Am <panam@nospam.com>
Subject: Re: Script for migrating HTML tree into a single directory ?
Message-Id: <1127718782.dec091df8ad9e40ce5405a7cc5f29972@teranews>

On Fri, 23 Sep 2005 13:13:35 -0400, Stan Brown wrote:

> Frankly, that statement stuns me. Or are you using some "hosting 
> service" that will wrap your actual pages in a lot of ads and 
> Javascript and similar crap?

not really... having very limited needs I use a free service: no
ads, limited space, single directory. Very basic, but ok for me.

> It would be hard to do, unless you can guarantee up front that 
> different directories don't contain files with the same names.
> But really, Web hosting isn't expensive these days, and any 
> "service" that limits you to a single directory is targeted at the 
> lower end. Since you have enough pages that you want a script because 
> hand editing is too cumbersome, you're really much better off with a 
> better host.

The script could prefix filenames to avoid duplications... 
Yet, if I cannot find it around I will look into paid services.

Thank you,

SJ





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

Date: Mon, 26 Sep 2005 00:33:20 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: script to run the program
Message-Id: <A-mdna_sWerfOareRVn-tA@comcast.com>

Josef Moellers wrote:
> a wrote:
> 
>> I need to run a program that need input at run time.
>> Is it possible to simulate this by perl?
> 
> It depends.
> You can open a pipe to the program and send the input through the pipe 
> (beware of buffering):
> open(DST, '|', $program);
> print DST "Input\n";
> 
> Or look at Perl/Expect.

For interactive use (where a line of input depends on something that
was output previously), a PTY-based solution (such as Expect.pm)
is the way to go. 
http://search.cpan.org/author/DJERIUS/Expect-Simple-0.02/Simple.pm

	-Joe


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

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


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