[19774] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1969 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 20 18:11:01 2001

Date: Sat, 20 Oct 2001 15: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: <1003615814-v10-i1969@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 20 Oct 2001     Volume: 10 Number: 1969

Today's topics:
        Grep and readdir NOSPAM@mail.spb.ru
    Re: Grep and readdir <jeff@vpservices.com>
    Re: Grep and readdir (Logan Shaw)
    Re: Grep and readdir NOSPAM@mail.spb.ru
    Re: Grep and readdir <jeff@vpservices.com>
    Re: Grep and readdir <jurgenex@hotmail.com>
    Re: Help: mail script (WIN) <bob@aol.com>
    Re: How do I get a list of files in a directory using p <bob@aol.com>
    Re: How to display text file in cgi-bin? (David Efflandt)
        http header for prompting Mac IE 5 downloading (James Liu)
        I want to write a perl script to get the bookmarks from <sj88@cornell.edu>
    Re: I want to write a perl script to get the bookmarks  (Tad McClellan)
    Re: lookingglass.pl <tsee@gmx.net>
    Re: lookingglass.pl <ilya@martynov.org>
    Re: Opening files... (Garry Williams)
    Re: Opening files... <nathan.randle@ntlworld.com>
    Re: perl script to summarize mail log <bob@aol.com>
    Re: Problem installing DBD (John J. Trammell)
        required package information <intmktg@gloria.cam.org>
    Re: required package information (Clinton A. Pierce)
    Re: required package information <intmktg@gloria.cam.org>
    Re: required package information <Tassilo.Parseval@post.rwth-aachen.de>
        requiring packages dynamically <intmktg@gloria.cam.org>
    Re: Scaling a DNA string <darkon@one.net>
    Re: Scaling a DNA string <please@no.spam>
    Re: splitting a very wide report <bob@aol.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 20 Oct 2001 10:02:49 +0000
From: NOSPAM@mail.spb.ru
Subject: Grep and readdir
Message-Id: <4pi2ttc58aeqf99vp6sguql91iritqsl71@4ax.com>

Hi !

I want to select in a table, all files that begin with for example
"abc" (like  abc_test.dat, abcdef.txt, etc).

The following seemed me correct, but it fails:
(the $path IS correct :)


opendir (DIR,"$path");
@filelist=grep(/abc/,readdir(DIR));
close(DIR);


Could anybody help ?

Thanks
Piotr


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

Date: Sat, 20 Oct 2001 11:21:02 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Grep and readdir
Message-Id: <3BD1C08E.F5EE452F@vpservices.com>

NOSPAM@mail.spb.ru wrote:
> 
> The following seemed me correct, but it fails:
> (the $path IS correct :)
> 
> opendir (DIR,"$path");
> @filelist=grep(/abc/,readdir(DIR));
> close(DIR);

First some acronyms you may not be familiar with:

  IDW    -- it doesn't work
  IF     -- it fails (a synonym for IDW)
  WTFDTM -- what the fudge does that mean

Some examples:

  You bring your body to your doctor and say IDW.
    She asks WTFDTM?
  You bring your car to your mechanic and say IDW.
    She asks WTFDTM?
  You bring your script to clpm and say IDW.
    We ask WTFDTM?

We also point out that you should never use file access methods like
opendir() without checking for errors and that "$path" has quote marks
on it that aren't needed.  We also wonder if your filenames are in upper
or lower or mixed case and if they're not all in lower case, whether
your grep pattern should be /abc/i.

-- 
Jeff



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

Date: 20 Oct 2001 13:30:55 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Grep and readdir
Message-Id: <9qsfsv$d9k$1@charity.cs.utexas.edu>

In article <3BD1C08E.F5EE452F@vpservices.com>,
Jeff Zucker  <jeff@vpservices.com> wrote:
>your grep pattern should be /abc/i.

Or /^abc/i.

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Sat, 20 Oct 2001 10:34:02 +0000
From: NOSPAM@mail.spb.ru
Subject: Re: Grep and readdir
Message-Id: <8hk2tt8973i3q5f2jooiena8eprm2mpoqk@4ax.com>

On Sat, 20 Oct 2001 11:21:02 -0700, Jeff Zucker <jeff@vpservices.com>
wrote:

>NOSPAM@mail.spb.ru wrote:
>> 
>> The following seemed me correct, but it fails:
>> (the $path IS correct :)
>> 
>> opendir (DIR,"$path");
>> @filelist=grep(/abc/,readdir(DIR));
>> close(DIR);
>
>First some acronyms you may not be familiar with:
>
>  IDW    -- it doesn't work
>  IF     -- it fails (a synonym for IDW)
>  WTFDTM -- what the fudge does that mean
>
>Some examples:
>
>  You bring your body to your doctor and say IDW.
>    She asks WTFDTM?
>  You bring your car to your mechanic and say IDW.
>    She asks WTFDTM?
>  You bring your script to clpm and say IDW.
>    We ask WTFDTM?
>

BTW, FYI, IDWLMT :)

>We also point out that you should never use file access methods like
>opendir() without checking for errors and that "$path" has quote marks
>on it that aren't needed.  We also wonder if your filenames are in upper
>or lower or mixed case and if they're not all in lower case, whether
>your grep pattern should be /abc/i.

- of course I didn't write the die sequence,
- YAR for the quotes that aren't requested but that are not prohibed
anyway..

- and if I wrote 'abc', that means 'abc' and *not* 'Abc' or 'ABC',
etc.

The 'abc' files are autogenerated and the 'abc' will always be in
lower case.


TFYH :)


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

Date: Sat, 20 Oct 2001 11:39:03 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Grep and readdir
Message-Id: <3BD1C4C7.578A8866@vpservices.com>

Logan Shaw wrote:
> 
> In article <3BD1C08E.F5EE452F@vpservices.com>,
> Jeff Zucker  <jeff@vpservices.com> wrote:
> >your grep pattern should be /abc/i.
> 
> Or /^abc/i.

Yes, right, I forgot about the "starts with" part.  OTOH, without
knowing what "fails" means we can't really know if either suggestion
will help since fails could mean no files were returned or that too many
files were returned or that only some of the files were returned, or
something else.

-- 
Jeff



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

Date: Sat, 20 Oct 2001 11:44:18 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Grep and readdir
Message-Id: <3bd1c605@news.microsoft.com>


<NOSPAM@mail.spb.ru> wrote in message
news:4pi2ttc58aeqf99vp6sguql91iritqsl71@4ax.com...
> I want to select in a table, all files that begin with for example
> "abc" (like  abc_test.dat, abcdef.txt, etc).
>
> The following seemed me correct, but it fails:
> (the $path IS correct :)
>
>
> opendir (DIR,"$path");
> @filelist=grep(/abc/,readdir(DIR));
> close(DIR);

No need to mess around with opendir, why not use simple globbing:
    @filelist=<abc*>;

jue




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

Date: Sat, 20 Oct 2001 19:20:41 GMT
From: Terrapin <bob@aol.com>
Subject: Re: Help: mail script (WIN)
Message-Id: <67j3ttspp7qc3295j44iqrrl68l68l52s3@4ax.com>

It will not matter where the mail was generated or which machine it
was sent from since the recipient will get from their "ususal" server.

On 24 Sep 2001 23:12:19 -0400, bill <bill02115@hotmail.com> wrote:

>In <9olr6j$j34$1@charity.cs.utexas.edu> logan@cs.utexas.edu (Logan Shaw) writes:
>
>>A fairly obvious way is to connect to some SMTP server somewhere
>>and spit the mail message at it.  You can do this with Net::SMTP.
>
>The mail must come from the "usual" SMTP server (i.e. the one used by
>the usual mail program when mail is sent from the machine in
>question).  The problem is, I can't figure out what this server's
>name/domain is.  Is there a program that will reveal that information?
>
>thanks,
>
>bill



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

Date: Sat, 20 Oct 2001 18:48:24 GMT
From: Terrapin <bob@aol.com>
Subject: Re: How do I get a list of files in a directory using perl?
Message-Id: <ufh3ttcannb4fpqs9676gvonoiddjqu1la@4ax.com>

On Tue, 25 Sep 2001 12:01:02 +0100, "W K" <bill.kemp@wire2.com> wrote:

>> > i am not familiar with parse_dir...is it part of a module? but anyway,
>> > the standard way to read the contents of a directory with perl is with
>> > opendir and readdir like this:
>>
>> And of course Perl offers alternative ways, too, e.g. globbing:
>>
>> @list = <*>;
>
>or another way of globbing:
>
>@list =glob ("/home/me/*.pl")
>
>
>
Or ...

@list = grep !-d, glob "/home/me/*.pl";

!-d checks to ensure no dir names included...


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

Date: Sat, 20 Oct 2001 15:55:44 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: How to display text file in cgi-bin?
Message-Id: <slrn9t37jv.pu3.efflandt@typhoon.xnet.com>

On Sat, 20 Oct 2001 08:59:02 -0500, Jerry McEwen <mail@mail.com> wrote:
> My host already told me that anything in the cgi-bin folder will have
> to be a cgi. Sure, I could change this (now that you have told me
> how), but I assume it is this way for security reasons. What is your
> thought on this? 

CGI can't do any more or less harm from cgi-bin than CGI allowed to run
elsewhere.  The difference is that the file extension does not matter for
anything in a ScriptAlias cgi-bin, it is ALL considered CGI.  It can
minimize the chance that source of cgi-bin files could be viewed from the
web.  But some misconfigured virtual hosts allow source access with a
different URL path (like hosting.domain/~username/cgi-bin/ or
hosting.comain/my.domain/cgi-bin/ vs. my.domain/cgi-bin/).  So that is
something to verify if trying to hide something.

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: 20 Oct 2001 15:04:23 -0700
From: jamesliu@sprynet.com (James Liu)
Subject: http header for prompting Mac IE 5 downloading
Message-Id: <7b939860.0110201404.2748228a@posting.google.com>

I am currently doing a project that allows the client to download
files from a site.   So basically I return the content of the file
with the following HTTP header:

Content-Type: application/force-download
Content-Disposition: attachment; filename="<attachment>"
Content-Transfer-Encoding: binary
Content-Length: <length>

It worked fine for both IE and Netscape on Windows, and Netscape
for Mac, but I just can't get IE5 for Mac to work with this piece
of code..  I have tried so many variations to the header, but
nothing worked.

I would appreciate any help that I can get!


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

Date: Sat, 20 Oct 2001 13:39:54 -0400
From: "Shi Jin" <sj88@cornell.edu>
Subject: I want to write a perl script to get the bookmarks from pdf file, please give some suggestion.
Message-Id: <9qsctn$pv4$1@news01.cit.cornell.edu>

I want to get the bookmarks from the pdf files and make one index of the
book.
Can anyone tell me something about the bookmarks? How to get it out? Is
there any software to deal with large number of files? If there is not, I
will write a perl script to get them out.
Any suggestion?
Thanks




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

Date: Sat, 20 Oct 2001 19:49:15 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: I want to write a perl script to get the bookmarks from pdf file, please give some suggestion.
Message-Id: <slrn9t3igt.28n.tadmc@tadmc26.august.net>

Shi Jin <sj88@cornell.edu> wrote:

>Can anyone tell me something about the bookmarks? 


The answer to that question will be the same regardless 
of what programming language you choose to use.

So it is off-topic in a language newsgroup.

Perl experts hang out here. The PDF experts hang out in the PDF group:

   comp.text.pdf


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


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

Date: Sat, 20 Oct 2001 20:10:08 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: lookingglass.pl
Message-Id: <9qsooq$leo$04$1@news.t-online.com>

"Tad McClellan" <tadmc@augustmail.com> schrieb im Newsbeitrag
news:slrn9t17in.v1c.tadmc@tadmc26.august.net...

[snip]

|    3) uses scalar(@array)-1 instead of $#array ( $#{$local_files[1]} )

Though I generally agree with you that the program isn't well written, I
recall there being some discussion about the use of $#{} versus @{}-1. IIRC,
there are a bunch of not-so-bad programmers out there who use @array-1.

Steffen

--
$_=q;33352987319029872958319011313364356732192639127636833335345138283712
3712336415083973397340602842912;;s;\n;;;print"\n";$o=$_;push@o,substr($o,
$_*4,4)for(0..24);pop@o;for(@o){$i++;print' 'x(26-$i).(chr$_/29-$i)."\n"}





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

Date: 21 Oct 2001 01:31:14 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: lookingglass.pl
Message-Id: <87hesuq9r1.fsf@abra.ru>

>>>>> On Sat, 20 Oct 2001 20:10:08 +0200, "Steffen Müller" <tsee@gmx.net> said:

SM> "Tad McClellan" <tadmc@augustmail.com> schrieb im Newsbeitrag
SM> news:slrn9t17in.v1c.tadmc@tadmc26.august.net...

SM> |    3) uses scalar(@array)-1 instead of $#array ( $#{$local_files[1]} )

SM> Though I generally agree with you that the program isn't well
SM> written, I recall there being some discussion about the use of
SM> $#{} versus @{}-1. IIRC, there are a bunch of not-so-bad
SM> programmers out there who use @array-1.

I hope I count as not-so-bad programmer :)

I never use $#array because I think it looks ugly. Of course it is my
'IMHO'. I'd like to know if there is anything wrong with usage of
@array in scalar context instead of $#array. I haven't heard any
reason against it yet. Moreover it seems that most programmers prefer
@array syntax. At least in all Perl sources I've seen @array is
preferred. I tried to find mentioned discussion with google but I
haven't found anything.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)          TIV.net (http://tiv.net/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Sat, 20 Oct 2001 16:09:40 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Opening files...
Message-Id: <slrn9t38e4.mts.garry@zfw.zvolve.net>

On Fri, 19 Oct 2001 19:13:03 +0100, Nathan Randle
<nathan.randle@ntlworld.com> wrote:

> I have started a script recently that uses the open command as shown
> below:
> 
> open(FILE,$file) or die("Can't open the file: $!");
> 
> $file is the name of a file that I wish to open. the problem is with
> using a variable like that. I have tried without the variable and it
> works fine but once it is added the server can't find the file.
> 
> Any ideas?

Hard to tell since you haven't supplied enough information.  

You can help yourself by choosing better diagnostic messages.  Always
print the file name in error messages about files.  

  open(FILE, $file) or die "Can't open '$file': $!\n";

-- 
Garry Williams


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

Date: Sat, 20 Oct 2001 17:24:08 +0100
From: "Nathan Randle" <nathan.randle@ntlworld.com>
Subject: Re: Opening files...
Message-Id: <pan.2001.10.20.17.24.06.639.739@ntlworld.com>

In article <pan.2001.10.19.19.13.03.61.2034@ntlworld.com>, "Nathan Randle"
<nathan.randle@ntlworld.com> wrote:

> I have started a script recently that uses the open command as shown
> below:
> 
> open(FILE,$file) or die("Can't open the file: $!");
> 
> $file is the name of a file that I wish to open. the problem is with
> using a variable like that. I have tried without the variable and it
> works fine but once it is added the server can't find the file.
> 
> Any ideas?
> 
> Thx, Nathan.

Stupid error. thx for the pointers next time I post I'll provide more
information becuase you would have needed it in this case.To let
you know, the problem was that there was an 'if' statement before the
variable declarations which made the script jump to a point beyond the
declarations. *doh!*


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

Date: Sat, 20 Oct 2001 18:20:06 GMT
From: Terrapin <bob@aol.com>
Subject: Re: perl script to summarize mail log
Message-Id: <shf3tt475hthotru72am9le7v2hdqdpcoi@4ax.com>

On 3 Oct 2001 22:23:21 GMT, s11976@net2.hkbu.edu.hk (PM WONG) wrote:

>Looking for a perl script (or sh script will do if it works)
>to give a summary of 
>Sender  Recipient   date/time   status(ok or not)
>
>by scanning the /var/spool/mqueue/syslog
>
>We run sendmail 8.9.x

I don't know what the sendmail logs look like, but how about something
like this?


#!/usr/bin/perl -w
use File::Copy;
@ARGV = grep !-d, glob "C:/SMTP/Stats/sm*.csv";
# Make an array of filenames, make sure not a dir name with !-d
switch.
while (<>) {
copy ($ARGV,"C:/SMTP/Stats/Archive");}
# Make a backup first!

($first) = @ARGV = grep !-d, glob "C:/SMTP/Stats/smtp*.csv";
# Sets variable $first to first file in dir to preserver header row,
# Builds array @ARGV of all file names in dir & verifies they are not 
# directories with !-d switch.

@now = localtime;
$mth = ($now[4]);
$yr = ($now[5]+1900);
# Sets date variables for file nameing.

open OUT, "> C:/SMTP/Stats/Stats for $mth-$yr.csv" 
or die "I can't create C:/SMTP/Stats/Stats for $mth-$yr.csv: $!";

while (<>) {
	    s/^"0/"200/g; # Change year (ie: 01 to 2001)
		s/^"1/"201/g; # Change year (ie: 18 to 2018)
		# Above valid until 01/01/2020.  That ought to be good
enough!  :)  Had to do this as our program creates date as yy-mm-dd
and when opened in Excel, it freaks out the date format...

if ($ARGV eq $first or $. !=1) # If first file, read all rows
{print OUT}
close ARGV if eof; # If EOF, reset counter & skip header row in other
files.
}
close OUT; # Unlock "SMTP Stats for $mth-$yr.csv" file.

# Next section is to delete orignal data files.
@OLDFILES = grep !-d, glob "c:/smtp/stats/sm*.csv";
unlink @OLDFILES; # Delete files in list @OLDFILES


Hope this helps you.  Oh, this runs on a Win2K server so you may need
to modify paths, etc. if using on Linux or other platform.



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

Date: Sat, 20 Oct 2001 11:21:16 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: Problem installing DBD
Message-Id: <slrn9t393s.i2g.trammell@haqq.hypersloth.net>

On 19 Oct 2001 16:29:41 -0400, Dave K. <david345@toast.com> wrote:
> 
> I'm trying to install the DBD::mysql Perl module, but I'm getting an
> error I'm not sure how to deal with.  It has to do with the linker
> flags -lz and -lgz.
> 
> I assume that these flags refer to libz and libgz, but I've come
> across stuff to suggest that -lz really refers to zlib, not libz.
> Which is it?
> 
> I was not able to find either libz or libgz at the Debian packages
> site.  A Google search was no help.  Where can I find these libraries,
> in either .deb or tar.gz/.tgz form?

I was unable to find a libgz, but my install went OK with just libz.
Debian package zlib1g-dev should do it.

-- 
The Internet: may contain traces of nuts.


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

Date: Sat, 20 Oct 2001 12:49:35 -0400
From: Marc Tardif <intmktg@gloria.cam.org>
Subject: required package information
Message-Id: <Pine.LNX.4.10.10110201244130.7395-100000@gloria.cam.org>

If package Foo is required in package Bar, how does
the latter keep track of which packages have been
required? This information needs to be stored somewhere
on a package basis so that Bar can now call Foo->sub
and not Blah->sub. I looked in the %Bar:: hash but
found nothing relating to 'Foo'. So where is the
required package 'Foo' in relation to 'Bar'?

Note: if this is covered in any documentation, please
point me there.

Marc



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

Date: Sat, 20 Oct 2001 17:57:15 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: required package information
Message-Id: <%ViA7.187160$K6.90157303@news2>

[Posted and mailed]

In article <Pine.LNX.4.10.10110201244130.7395-100000@gloria.cam.org>,
	Marc Tardif <intmktg@gloria.cam.org> writes:
> If package Foo is required in package Bar, how does
> the latter keep track of which packages have been
> required? This information needs to be stored somewhere
> on a package basis so that Bar can now call Foo->sub
> and not Blah->sub. I looked in the %Bar:: hash but
> found nothing relating to 'Foo'. So where is the
> required package 'Foo' in relation to 'Bar'?

Not to be difficult, but I smell an XY question.  If I've got
in Foo.pm:

	require "Bar";

And later in Bar.pm I want to tell who included me...why should I 
care?  It sounds like you're going on about inheritance which is
handled with an entirely different mechanism (@ISA).  Best bet is
to start with one of the OO tutorials and read up on inheritance.

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


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

Date: Sat, 20 Oct 2001 13:33:18 -0400
From: Marc Tardif <intmktg@gloria.cam.org>
Subject: Re: required package information
Message-Id: <Pine.LNX.4.10.10110201329310.7480-100000@gloria.cam.org>

On Sat, 20 Oct 2001, Clinton A. Pierce wrote:

> In article <Pine.LNX.4.10.10110201244130.7395-100000@gloria.cam.org>,
> 	Marc Tardif <intmktg@gloria.cam.org> writes:
> > If package Foo is required in package Bar, how does
> > the latter keep track of which packages have been
> > required? This information needs to be stored somewhere
> > on a package basis so that Bar can now call Foo->sub
> > and not Blah->sub. I looked in the %Bar:: hash but
> > found nothing relating to 'Foo'. So where is the
> > required package 'Foo' in relation to 'Bar'?
> 
> Not to be difficult, but I smell an XY question.  If I've got
> in Foo.pm:
> 
> 	require "Bar";
> 
> And later in Bar.pm I want to tell who included me...why should I 
> care?  It sounds like you're going on about inheritance which is
> handled with an entirely different mechanism (@ISA).  Best bet is
> to start with one of the OO tutorials and read up on inheritance.
> 
Sorry, I mixed Bar and Foo in the last part of my
question. What I wanted to ask was:
in Foo.pm which requires "Bar", as demonstrated in the
example above, how can Foo.pm know that it included
"Bar".

Marc



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

Date: Sat, 20 Oct 2001 23:31:54 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: required package information
Message-Id: <3BD1ED4A.90202@post.rwth-aachen.de>

Marc Tardif wrote:


> Sorry, I mixed Bar and Foo in the last part of my
> question. What I wanted to ask was:
> in Foo.pm which requires "Bar", as demonstrated in the
> example above, how can Foo.pm know that it included
> "Bar".


The information are to be found in the package's symbol-table. Try the 
following on the command line:

% perl -e 'print %main::'     (or %:: likewise)

After importing functions and variables (symbols in general) from 
another module, these are added to the importing package's symbol-table. 
That's what is meant with namespace and why it should not be polluted 
without reason. So, a lot of modules only export stuff on demand, such as

use Term::ANSIColor qw(:constants);

where the qw-parts specifies a tag that will make the module export the 
constants as well. You can see the difference now if you type:

% perl -MTerm::ANSIColor=:constant -e 'print %main::'

A lot of stuff such as YELLOW, RED etc should now be listed as well. 
That's because these symbols have been imported.

In case of object-oriented modules that often do not export anything: 
You create an object...this is usually a reference bless()ed into a 
class. That means, you can even find out yourself to which class an 
object belongs with 'print ref $obj'. In this case ref() behaves 
similarily to Java's instanceof-operator.


Tassilo


-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Sat, 20 Oct 2001 13:57:46 -0400
From: Marc Tardif <intmktg@gloria.cam.org>
Subject: requiring packages dynamically
Message-Id: <Pine.LNX.4.10.10110201355140.7528-100000@gloria.cam.org>

Is there a portable way to require a package after
building its name dynamically? For example:

foreach (qw(Foo Bar)) {
	my $package = "One::Two::$_";
	require $package;
}

The problem with the above is that since $package
is a scalar, require expects an explicit path to
the package name so I'd have to declare $package
as:

my $package = "/path/One/Two/$_.pm";

Unfortunately, this is not portable and rather
limited compared to letting Perl use the @INC
array. So is there a way around this problem?

Marc



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

Date: 20 Oct 2001 18:16:26 GMT
From: "David K. Wall" <darkon@one.net>
Subject: Re: Scaling a DNA string
Message-Id: <Xns9140916FF9DBAdarkononenet@130.133.1.4>

mgjv@tradingpost.com.au (Martien Verbruggen) wrote:

> Ok, now that a few of the questions have been settled, here's a small
> subroutine that (I think) does what you want. It seems rather longish,
> but most of it is comments.
> 
> Before relying on its correctness, let it float around this group for
> a few days. I suspect that I made an error here or there, or that
> someone has a faster way to do what I do with my two substitutions.
> Also, it is possible that I still have misunderstood things.

I've misunderstood them the same way, because what I came up with produces 
about the same output as yours and Benjamin's solutions, although mine is 
not nearly as Perlish and tidy.  It's almost certainly slower, too, as I 
make several passes through the data, but I've not tested it for speed.  It 
uses the positions of the beginning of the motifs, not the ends, so the 
output is slightly different.  I was pondering on how to encode the varying 
numbers of G and C motifs, so I stole code from your post.  (I stole a bit 
more than just that, so part of what follows will look very familiar.)

There's probably a clever way of eliminating the second for() loop and 
doing it all in the first, but it's not immediately obvious to me.

I modified this from a previous attempt. (which was also based on your 
ideas, Martien :-)

I hesitate to post this; it seems primitive.  But what the hell, I might as 
well.  It wouldn't be the first time I've posted ugly code to this 
newsgroup.


use strict;
use warnings;

while (<>)
{
    my ($gene, $name) = split ' ', $_, 2;
    my $pgene = parse_gene($gene, 50);
    print "$pgene $name";
}


sub parse_gene { 
    my ($sequence, $code_length) = @_;
    
    my $group_size = length($sequence) / $code_length;

    die "Code length must divide the sequence length evenly!" 
        if ($group_size - int($group_size)); #maybe I should have used mod?

    $sequence =~ s/(C{4,}|G{4,})/lc $1/ge;
    $sequence =~ tr/AGTC/-/;
    $sequence =~ s/(-+)/" ".(length $1)." "/ge;
    $sequence =~ s/^ +//;

    # at this point we have something that looks like
    #11 gggg 169 ggggg 33 cccc 53 cccc 349 ggggg 133 cccc ...

    my $count = 1;
    my %run=(); 
    for ( split /\s+/, $sequence ) {
        my $position = $count + 1;
        if ( /\d+/ ) { 
            $count += $_ - 1;
        }
        else { 
            $count += length($_) + 1;
            # remember a run at $position
            $run{$position} = /g/ ? 'g':'c';
        }
        
    }
    
    # This is pretty ugly.  What I'm calling a "group" is a single
    # encoded character representing $group_size characters in the 
    # original gene sequence.  I loop over 1..length($sequence) and
    # count the number of runs of G and C in a group using the 
    # %run hash, then use Martien's encoding scheme to represent the 
    # numbers found.
    my $coded;
    for (my $group=0; $group <= $code_length - 1; $group++) {
        my ($ng, $nc) = (0,0);
        for (my $base=1; $base <= $group_size; $base++) {
            my $position = $group * $group_size + $base;
            if (exists $run{$position}) { 
                ++$ng if $run{$position} eq 'g';
                ++$nc if $run{$position} eq 'c';
            }
        }
        $coded .= ($ng && $nc) ? "*"
                : ($ng  > 1  ) ? "G"
                : ($ng == 1  ) ? "g"
                : ($nc  > 1  ) ? "C"
                : ($nc == 1  ) ? "c"
                :                "-" ;
    
    }
    return $coded;
}
__END__


-- 
David Wall 
darkon@one.net


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

Date: Sat, 20 Oct 2001 21:04:31 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: Scaling a DNA string
Message-Id: <874rouc9f2.fsf@homer.cghm>


[Snip discussion on representing long strings of genetic code using
ASCII text]

I have to wonder, is there a specific reason you're limited to ASCII
text here?  It seems the best and easiest solution would involve some
form of pixel-based graphics, if available.  It is inherently
difficult to represent a lot of information in a little space at bad
resolution.  Is it possible just to increase the resolution?


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

Date: Sat, 20 Oct 2001 18:38:58 GMT
From: Terrapin <bob@aol.com>
Subject: Re: splitting a very wide report
Message-Id: <a0h3tt07b0p14cthvif2qdro8a4vltvepa@4ax.com>

I would say run the report and then split it on columns.  See
http://www.devdaily.com/perl/edu/articles/pl010016/ for tips on how to
split using columns.


On Mon, 01 Oct 2001 10:35:31 -0400, Marc Ulrich
<mdulrich@unity.ncsu.edu> wrote:

>I've a report output that is very very wide and is better done as three
>individual reports (which will fit on a single page). Line wraps are
>annoying and so is ultrasmall text.
>
>The only solution I've come up with is to have three output formats and
>do three separate reports. This is kind of awkward. I'd rather do a
>single report but ask it to split it after column x and after column y.
>Is this possible?
>
>Thanks,
>Marc



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

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


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