[24333] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6522 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 5 09:05:47 2004

Date: Wed, 5 May 2004 06:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 5 May 2004     Volume: 10 Number: 6522

Today's topics:
    Re: Books online???? <catcher@linuxmail.org>
    Re: calculate date 4 days ago (joe shaboo)
    Re: Chat Server and Time Delay <usenet@morrow.me.uk>
    Re: Creating Dynamic variables from CGI.pm Param() <mark.clements@kcl.ac.uk>
    Re: Editing a alias file  issue <mark.clements@kcl.ac.uk>
    Re: Help Needed Building Array Of Hashes From CSV (Anno Siegel)
    Re: Help Needed Building Array Of Hashes From CSV <tsheetspublic@insightbb.com>
    Re: Help Needed Building Array Of Hashes From CSV <tsheetspublic@insightbb.com>
    Re: Help Needed Building Array Of Hashes From CSV <tsheetspublic@insightbb.com>
    Re: Help Needed Building Array Of Hashes From CSV <tsheetspublic@insightbb.com>
    Re: How to hide "if $DEBUG" code? <mark.clements@kcl.ac.uk>
    Re: Komodo as a editor? <catcher@linuxmail.org>
    Re: Newbie question, logical operators (Anno Siegel)
    Re: Newbie question, logical operators <xxala_qumsiehxx@xxyahooxx.com>
    Re: Not sure if Perl or browser problem..... (Jamie)
    Re: Where's documentation for import ??? <aman_DO_da345@al_THE_ter_OBVIOUS_n.org>
    Re: Where's documentation for import ??? <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 05 May 2004 06:46:31 -0400
From: Robert <catcher@linuxmail.org>
Subject: Re: Books online????
Message-Id: <dZadnSBoTJ6UWwXd4p2dnA@adelphia.com>

Henry Williams wrote:
> On Tue, 04 May 2004 21:37:06 -0400, Robert <catcher@linuxmail.org>
> wrote:
> 
> 
>>That makes no sense at all. So maybe my post should have been harsher. 
>>Basically what you are saying is "don't bother me". The reasons you give 
>>for not notifying O'Reilly are rediculous. You should have just said "I 
>>don't want to be bothered." and left it at that. Instead you give 
>>non-sensical reasons for not doing the *right* thing. I can only hope in 
>>real life you are a more ethical person.
>>
>>Robert
> 
> 
> 
> Robert you seem to be a fair-minded person. What I sought to point out
> is that once I have undertaken the task of policing O'Reilly's
> copyrights, I would, as an "ethical" person, scarcely have any
> stopping point. If I found a copyright violation, and reported it to
> O'Reilly, would I not then be obligated to be "on guard" on O'Reilly's
> behalf in all my coming and goings on the Net?
> Would it not be true at that point I would have undertaken a new
> profession, that of copyright assuror?

These is a difference between *actively* searching for such online 
stuff, which is not what I am talking about, and reporting stuff that 
you do *stumble* across. I am sure that since my first email about a 
violation that O'Reilly is not sitting behind his desk wondering when 
"Robert" is going to send in another violation report. I do not feel the 
compulsion to just be surfing looking for violators on their behalf. 
When I do run across what I consider a violation I report it. I 
appreciate the time and effort that the book authors put into something 
that I can buy and use repeatedly, so I find it a reasonable thing.

> 
> As for my poor "airport" analogy, what I refer to is the old scenario
> of the person making the compliant becoming the first suspect. I would
> reference an Edgar Allen Poe story to support my assertion, have you
> read "The Black Cat" ?

I have, but here is the point. That is just a story. I choose to live my 
life free from stereotypes found in stories. Nor do I believe, O'Reilly 
is thinking "Hmmm, Robert reported something. Ah ha! He must be doing it 
too!". I think that they do appreciate the effort made on their behalf 
and the authors behalf.

> I have little hiding in my walls, however attention is not what one
> wishes to draw to oneself. And if that single aspect of my character
> renders me in someone's eyes as unethical paint me unethical.

There is probably a fine line but unethical would be to *use* what you 
found and not report it. My point is made by your statements though. You 
just don't want to be bothered. End of story. No need for futher 
conversation.

Thanks for listening...

Robert


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

Date: 5 May 2004 05:53:05 -0700
From: jshaboo@hotmail.com (joe shaboo)
Subject: Re: calculate date 4 days ago
Message-Id: <f6d34657.0405050453.2517af4c@posting.google.com>

Jon Ericson <Jon.Ericson@jpl.nasa.gov> wrote in message news:<rcgad0nvjfx.fsf@Jon-Ericson.sdsio.prv>...
> Jim Cochrane <jtc@shell.dimensional.com> writes:
> 
> > In article <rcgisfbvr79.fsf@Jon-Ericson.sdsio.prv>, Jon Ericson wrote:
> >> jshaboo@hotmail.com (joe shaboo) writes:
> >> 
> >>> I'm trying to list files that are 4 days old, and then perform an
> >>> action on them. I don't care about any files that are newer (have been
> >>> edited or touched in the last 4 days), only 4 days or older.
> >>>
> >>> I can do this either through SHELL or perl, which ever is easier. 
> >> 
> >> Using option 1:
> >> 
> >>   $ find . -mtime -4
> >
> > For files 4 days or more older, I believe what is needed is: -mtime +4
> > (Check man find to be sure.)
> 
> Right.  My manpage says:
> 
>    TESTS
>        Numeric arguments can be specified as
> 
>        +n     for greater than n,
> 
>        -n     for less than n,
> 
>        n      for exactly n.
> 
> It's also posible that -atime would be required instead of -mtime.
> 
> > and you can do (in bash or ksh):
> >
> > process() {
> > 	: Do whatever with $1
> > }
> >
> > for file in $(find . -mtime +4 -exec grep -l 'pattern' {} ';'); do
> > 	process $file
> > done
> 
> I'm not sure what the point of using a function is.  I'd probably
> write something like:
> 
>   $ find . -mtime +4 | xargs whatever
> 
> (As you can tell, I sometimes have trouble remembering the find
> syntax. ;)
> 
> Jon

Right you are. I am sorry about the gibberish I posted. I actually
noticed it just as I reread the message on the board, but I figured
people could get the gist of the problem. I could reverse the
situation for which ever case I needed (older or newer than 4 days).

In any event, the simplest method for my means is to use the find
command with the -mtime. I had forgotten about that flag.

So, again thanks for your responses.

Joe


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

Date: Wed, 5 May 2004 10:07:36 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Chat Server and Time Delay
Message-Id: <c7aed8$56c$1@wisteria.csv.warwick.ac.uk>


Quoth Mark Clements <mark.clements@kcl.ac.uk>:
> Brian wrote:
> 
> > First one sits on a server and runs without being called
> > from a browser. It's job is to check the time, and if
> > the time = X then do Y. basically I want a script that
> > is going to clear a MySQL Db at 4 am every day
>
> use cron, or the equivalent on windows (Scheduled Tasks?). This will
> automatically execute a specified command according to whatever schedule you
> set.

We seem to be getting this quite a lot atm. Would it be worth writing a
faq answer?

Ben

-- 
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t    # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.


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

Date: Wed, 05 May 2004 11:22:10 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Creating Dynamic variables from CGI.pm Param()
Message-Id: <4098c046$1@news.kcl.ac.uk>

Julia deSilva wrote:

> I use something like this to process form elements
> 
> my $field;
> foreach $field ($q->param()) {
>         ${$field}  = $q->param($field);
>         .....
>         .....
> }
> 
> to retreive data from a dynamically created webpage where I do not know
> either the number or names of the form elements.
Yet you're willing to create variables with the names of them without any further validation?
Even if you knew the names of the form elements, this would be a bad idea as there is nothing to 
stop someone slapping up a web page anywhere that submits to your script.

> The above can't work under strict.
!!!!

> Some pointers would be very gratefully received.
you want to check out Vars and (shudder) import_names from CGI.

Mark


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

Date: Wed, 05 May 2004 11:34:10 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Editing a alias file  issue
Message-Id: <4098c317$1@news.kcl.ac.uk>

Ash wrote:

> (i.e. the left side elements) as the keys and everything on the right to 
> it the value. Then I tried to  sort the keys. The problem is if the new 
> alias lines are lets say plain appended to the list and then the list is 
> sorted with the hash using the  'cmp' operator, it still does not work 
> as desired.
How are you parsing the aliases file and what data structure are you creating from it? Exactly 
what arguments to sort are you subsequently using to sort this data? Is the sorting critical for 
the application? MTAs of which I have recent experience (Exim and (gulp) sendmail) don't care, 
though admittedly I rarely use tables like this without building a db file from them and using that.

> Database is not an option as of now.
maybe not, but it is probably the best solution to this problem, even if you only keep the data 
in a csv file. You could also check out DBD::SQLite. At the moment you are effectively trying to 
reverse engineer the aliases file.

Mark


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

Date: 5 May 2004 11:32:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help Needed Building Array Of Hashes From CSV
Message-Id: <c7ajd0$j2s$1@mamenchi.zrz.TU-Berlin.DE>

Tim Sheets  <tsheetspublic@insightbb.com> wrote in comp.lang.perl.misc:
> Hello group,
> 
> I am rather new to Perl (and programming in general) and am having a 
> problem building a hash.  I have read several tutorials, examples, etc.. 
> but nothing touches on exactly what I am trying to do.
> 
> I am trying to read data in from a CSV file (Excel export) and store the 
> information in an array of hashes.  The first line of the file contains 
> field names, and the following lines contain data.
> 
> So, I am reading the first line into an array, splitting on the commas, 
> to use as the hash keys.  Then all subsequent lines are read into 
> another array, splitting on the commas to be used as the values.

As has been noted, there are modules on CPAN that deal with CSV.

> Then I am trying to build another array, and combine the 'keys' and 
> 'values' from the first two arrays as a hash.
> 
> Here is the code I am trying to use:
> 
> # Begin reading csv dump
> open (REFERENCEFILE,"$ARGV[1]") ;

The quotes around "@ARGV[1]" do nothing useful.  They shouldn't be there.

> $count=0;

You're not running under "strict", are you?  You should, and switch
warnings on too.

> while (<REFERENCEFILE>) {
>    if ($count == 0) {
>      @refdatakeys = split(/,/, $_);

The last key will have a linefeed tacked on.  You ought to chomp
the line first.

>      $numelements = scalar (@refdatakeys);

It would be easier to read the first line by itself and not bother
with the line count.

"scalar" is redundant in the assignment of $numelements, it is already
in scalar context.  But you don't need $numelements at all (see below).

>    } else {
>      @refdatavalues = split(/,/, $_);

Again, there will be a linefeed appended to the last value.

>      for ($i=0; $i < $numelements; $i++) {

You don't need an indexed loop if you build the individual hashes
correctly.

>        @arrefdata = ({$refdatakeys[$i] => '$refdatavalues[$i]'});

This assigns a single hashref (which contains a single key/value pair)
to @arrefdata.  @arrefdata will never accumulate anything that way.
This is probably the central problem of your code.

>      }
>    }
> 
> print ("SITE ID is: $arrefdata[$count]{'SITE ID'}\n");
> $count++;
> }

So here is a way to do what you want:

    my ( @refdatakeys, @arrefdata);

    for ( scalar <REFERENCEFILE> ) {
        chomp;
        @refdatakeys = split /,/;
    }

    while ( <REFERENCEFILE> ) {
        chomp;
        my %row;
        @row{ @refdatakeys} = split /,/;
        push @arrefdata, \ %row;
    }

Anno


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

Date: Wed, 05 May 2004 12:37:20 GMT
From: Tim Sheets <tsheetspublic@insightbb.com>
Subject: Re: Help Needed Building Array Of Hashes From CSV
Message-Id: <4e5mc.27146$IG1.1153180@attbi_s04>

Jim Cochrane wrote:

> In article <%iYlc.24520$TD4.3466652@attbi_s01>, Tim Sheets wrote:
> 

> I could read your code and guess, but instead, it might save time
> to first ask: What exactly are you trying to do?  You're describing
> the problem in terms of an implementation, but I don't see any precise
> problem description mentioned or implied from the above description (maybe
> imprecise, but that's not good enough for a computer).  In other words,
> what are the requirements for your problem?  (If you decide to spend
> the time to become good at programming, you'll learn that being able to
> state the problem without mentioning or implying an implementation is
> one important skill you will need.)
> 
> Once your requirements are clear, people can then help you find a solution -
> an implementation.
> 

Jim,

You may have a point there regarding my ability to "properly" ask a 
question, but reading the above text, I am completely confused.  Maybe I 
am just dense, but about all I can understand is you aren't happy with 
the presentation of my question/problem.

I thought I did a pretty good job explaining what I was trying to do, 
and what was working, and what wasn't working (the latter two being 
after the code I posted).  Maybe I was too verbose, I dunno.

Thanks anyway,

Tim



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

Date: Wed, 05 May 2004 12:40:11 GMT
From: Tim Sheets <tsheetspublic@insightbb.com>
Subject: Re: Help Needed Building Array Of Hashes From CSV
Message-Id: <Lg5mc.27292$TD4.3870437@attbi_s01>

> "Tim Sheets" <tsheetspublic@insightbb.com> wrote in message
> news:%iYlc.24520$TD4.3466652@attbi_s01...
> 
>>Hello group,
>>
>>I am rather new to Perl (and programming in general) and am having a
>>problem building a hash.  I have read several tutorials, examples, etc..
>>but nothing touches on exactly what I am trying to do.
>>
>>I am trying to read data in from a CSV file (Excel export) and store the
>>information in an array of hashes.  The first line of the file contains
>>field names, and the following lines contain data.

George Kinley wrote:

 > Not asking to piss you off but just curious
 > Why did you thought of using Hash?
 >

It just seemed to make sense.  Would be easier to reference the fields 
of the CSV with names, rather than index numbers.  If the CSV file 
format changes, I think it would be easier to tweak the code if names 
were used instead of the index numbers.

Maybe you have a better way in   mind??  If so, I am open to suggestions.

Tim



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

Date: Wed, 05 May 2004 12:46:53 GMT
From: Tim Sheets <tsheetspublic@insightbb.com>
Subject: Re: Help Needed Building Array Of Hashes From CSV
Message-Id: <1n5mc.28114$_41.2038911@attbi_s02>

Tore Aursand wrote:

> On Wed, 05 May 2004 02:28:11 +0000, Tim Sheets wrote:
> 
>>open (REFERENCEFILE,"$ARGV[1]") ;
> 
> 
> Always check the outcome of an 'open()', and drop those unneeded double
> quotes;
> 
>   open( REFERENCEFILE, '<', $ARGV[1] ) or die "$!\n";
> 

You're correct.  I should be doing this.

> 
>>$count=0;
> 
> 
> You're not using 'strict' (and possible not 'warnings' either).  Make sure
> your script starts with (something like):
> 
>   #!/usr/bin/perl
>   #
>   use strict;
>   use warnings;

right again. :-)


<snip>

> Instead of using your own routine to parse CSV, you should consider one of
> the CSV modules on CPAN - <http://www.cpan.org/> - or Text::ParseWords
> (which comes with Perl).

I thought of that, but decided to try to make it happen myself.  More 
portable if you don't have to install an additional module, and as much 
as anything, I have never been able to get an array of hashes to work 
beyond tutorial examples I have found, and just wanted to tackle it 
again.  One of these days I will figure it out.


> Consider comparing the "length" of @refdatakeys and @refdatavalues in the
> code above, and consider doing something "smart" when there's a "length"
> mismatch.

hmmmm....good point. I think in my particular case, it won't matter, if 
I have an empty field, I want to keep it that way, but I can see where 
this wouldn't always be the case.

Tim



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

Date: Wed, 05 May 2004 12:48:41 GMT
From: Tim Sheets <tsheetspublic@insightbb.com>
Subject: Re: Help Needed Building Array Of Hashes From CSV
Message-Id: <Jo5mc.27190$IG1.1154670@attbi_s04>

Joe Smith wrote:

> Tim Sheets wrote:
> 
>>     for ($i=0; $i < $numelements; $i++) {
>>       @arrefdata = ({$refdatakeys[$i] => '$refdatavalues[$i]'});
>>     }
> 
> 
> I expect that you meant
>       $arrefdata[$count] = { key1,val1, key2,val2, key3,val3, ...}
> 
> You ought to create dummy column labels if any row has more items than
> the first row of the file.  Use map{}() to build a list of key/value pairs.
> 
>     my @temp = map { ( ($_ < @refdatakeys ? $refdatakeys[$_] : "unknown 
> $_"),
>               $refdatavalues[$_] ) } foreach (0 .. $#refdatavalues);
>     $arrefdata[$count] = { @temp };
> 
>     -Joe

Thanks, Joe, I'll look at that.  Could be very handy...

Tim



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

Date: Wed, 05 May 2004 13:57:42 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: How to hide "if $DEBUG" code?
Message-Id: <4098e4bb$1@news.kcl.ac.uk>

Eric Schwartz wrote:

> I use a similar convention, developed in a shop I worked in a few
> years ago:
> 
> DebugMsg($msg); # prints "$0: DEBUG: $msg" if $opt_debug is defined
> InfoMsg($msg);  # prints "$0: INFO: $msg"
<snip>
I like Log::Log4perl. It allows you to configure debug output format and change debug 
destination from a central config file. It probably isn't the most efficient of performers 
though; I doubt if anything is optimized away...

Mark


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

Date: Wed, 05 May 2004 06:52:24 -0400
From: Robert <catcher@linuxmail.org>
Subject: Re: Komodo as a editor?
Message-Id: <dZadnSNoTJ71WgXd4p2dnA@adelphia.com>

Robin wrote:

> "Robert" <catcher@linuxmail.org> wrote in message
> news:hJGdnQRF9eMnhAXdRVn-jw@adelphia.com...
> 
>>I am evaluating Komodo as an editor for work. I am doing a lot of Perl
>>work as a sysadmin and am starting to get into Perl/Tk as well. We use
>>PVCS for version control and I see Komodo integrates with that.
>>
>>All that to say "Do you use it and what do you think about it?".
>>
>>Robert
> 
> 
> I haven't tried Komodo, but I've read it's good. I like optiPerl, myself,
> even though you have to change a lot of settings to get it to work well. It
> might be the same way with komodo too, a lot of those dlls, etc are
> traded/sold from company to company, but if you want to try it, try it
> man...
> -Robin

I tried OptiPerl and it seemed a little sluggish. This was about a year 
ago. What I looking at that most is the UI builder in Komodo.

I will take a look at OP again though.

Thanks,

Robert


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

Date: 5 May 2004 10:25:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Newbie question, logical operators
Message-Id: <c7afe9$ehd$1@mamenchi.zrz.TU-Berlin.DE>

Zachary Turner <zturner_NOSPAM_0826@hotmail.com> wrote in comp.lang.perl.misc:
> Coming from a C++ background, I'm very familiar with logical operators, but
> why in Perl do they work the way they do?  It doesn't seem like the
> operators are logically the same.  Take an example: a = 0, b = 10.

[C++ returns a boolean, Perl returns the value that determines the result]

> So in these two situations, we can see there is a difference in the two.  I
> can see how logically speaking the operators WORK, but what is the reason
> for returning the value?  It seems like you can't ever know what you're
> getting back.

If you really need to know what you are getting back (above its boolean
value, which you do know), you can use double negation:

    !!( $x || $y)

That will predictably give you 1 for true and "" for false.

Anno


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

Date: Wed, 05 May 2004 12:08:33 GMT
From: Ala Qumsieh <xxala_qumsiehxx@xxyahooxx.com>
Subject: Re: Newbie question, logical operators
Message-Id: <5P4mc.60446$X76.31120@newssvr25.news.prodigy.com>

Zachary Turner wrote:
> "Ala Qumsieh" <xxala_qumsiehxx@xxyahooxx.com> wrote in message
> news:4Q_lc.45162$jC3.28888@newssvr29.news.prodigy.com...

> Sigh...  I didn't imply that it SHOULD conform to my "C++ expectations", it
> was just something that surprised me and I couldn't think off the top of my
> head of how it might be useful, although I knew that there were probably
> many common idioms using it.  Hence I posted to the newsgroup, pointing out
> that I realize they are logically equivalent, I just wanted an example of
> how it's useful.

Sorry. Didn't mean to sound condescending. Effect of late night posting :)

>>Sure. There are many common idioms that are used. Some examples:
>>
>>1.  open(FH, $file) || die "Can't open $file: $!\n";
>>2.  my $val = $ENV{USER} || 'nobody';
>>3.  defined($x) && print "X = $x";
>>4.  my $arg = shift || 'default_value';
> 
> Thanks.
> Can you come up with one or two using && that set the result equal to
> something and then use that result in some way?

Admittedly, and as pointed out by others, my examples 1 & 3 have nothing 
to do with && and || returning one of their operands' values. As for an 
example using &&, the only thing I can think of is this. Instead of:

	$x = $flag ? $y : $z;

you can do:

	$x = $flag && $y || $z;

but in this case I would argue against it since it's more cryptic, and 
even longer to type.

--Ala



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

Date: 5 May 2004 05:47:23 -0700
From: jnunner@hotmail.com (Jamie)
Subject: Re: Not sure if Perl or browser problem.....
Message-Id: <dc2a9475.0405050447.163025a4@posting.google.com>

> If the Win95/IE5.5 client can still talk to the server and get the
> right result then this must be a browser issue.  However if that's not
> what you are saying then I'd guess it's very unlikely to be a browser
> issue.
> 

Yes...the Win95/IE5.5 client could talk to the server and get the
right result, that's why I'm positive its a browser issue...the only
other thing I can think of is that the new system is missing some sort
of driver or plugin.  Is that possible??

> 
> Well since this is most likely to be a web server issue then one bit
> of useful info would be what web server you are using.

I'm using a small web server software that was recommended by one of
my Perl books, called "Xitami"...i'm not using this to host the site
at all...I installed this purely to test the perl scripts, as
suggested by the book.
:P


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

Date: Wed, 5 May 2004 10:35:56 +0000 (UTC)
From: Amanda <aman_DO_da345@al_THE_ter_OBVIOUS_n.org>
Subject: Re: Where's documentation for import ???
Message-Id: <c7ag2c$4rh$1@reader2.panix.com>

In <c797pt$9si$1@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:

>Quoth Amanda aman_DO_da345@al_THE_ter_OBVIOUS_n.org:

>> Yes, I have read perlfunc on "use" and "import", and I have read
>> perlmod, and I have read the manpage for Exporter.  None of these
>> documents comes even close to explaining what import is supposed
>> to do; they don't even explain what import's input and output
>> signatures are.

>I'm not sure... could you explain

I thought I was perfectly clear.  I want to understand *exactly*
what import is supposed to do.  The cute (and/or disingenuous)
answer to this question is "import can do whatever you want it to
do"--i.e. a perfectly worthless API in a nutshell.  A less cute,
but almost as worthless, answer would be, "import is supposed to
do what the canonical example of import, namely Exporter's, does".
Unfortunately the Exporter man page does not say a word about what
its import does.

I really don't understand why the Perl documentation has chosen to
be so coy on import; it treats Perl programmers like children who
shouldn't be trusted with such sensitive information (which makes
the ubiquitous little sermons on programmer responsibility all
throughout the documentation all the more annoying).  The fact that
import is not a built-in is a technicality.  It is every bit as
important as many built-ins (e.g. "use"), and it deserves to be
better documented.

And no, source code is no substitute for documentation (otherwise
many trees should have been saved by never printing the Camel book
and its ilk).

Amanda
-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: Wed, 5 May 2004 11:05:00 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Where's documentation for import ???
Message-Id: <c7ahos$7mk$1@wisteria.csv.warwick.ac.uk>


Quoth Amanda <aman_DO_da345@al_THE_ter_OBVIOUS_n.org>:
> In <c797pt$9si$1@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:
> 
> >Quoth Amanda aman_DO_da345@al_THE_ter_OBVIOUS_n.org:
> 
> >> Yes, I have read perlfunc on "use" and "import", and I have read
> >> perlmod, and I have read the manpage for Exporter.  None of these
> >> documents comes even close to explaining what import is supposed
> >> to do; they don't even explain what import's input and output
> >> signatures are.
> 
> >I'm not sure... could you explain
> 
> I thought I was perfectly clear.  I want to understand *exactly*
> what import is supposed to do.  The cute (and/or disingenuous)
> answer to this question is "import can do whatever you want it to
> do"--i.e. a perfectly worthless API in a nutshell.

Hmmm. It's correct though: a module's import method can do whatever it
wants. It's inputs are clear: import is passed whatever is given to use.
The only thing that is perhaps unclear is that its output is completely
ignored: only its side-effects matter.

Do you understand the concept of a 'hook', or a 'callback'? This is what
import is: an opportunity for a module to do (whatever it likes) at
'use' time.

> A less cute, but almost as worthless, answer would be, "import is
> supposed to do what the canonical example of import, namely
> Exporter's, does".  Unfortunately the Exporter man page does not say a
> word about what its import does.

It exports subs into the caller's namespace: that is, if Foo inherits
Exporter's import then after executing

package main;
Foo->import(qw/bar baz/);

the subs Foo::bar and Foo::baz are also available as main::bar and
main::baz.

 . This is by far the most common thing for a module's import to do; it
can do all sorts of other things, though. For instance, strict::import
sets certain perl-internal variables that put the Perl parser into
strict mode.

If you like, import is supposed to do whatever the documentation for the
module states it should do.

Can you give an example of something you are trying to achieve, so we
can show you how to create an import sub that does it?

Ben

-- 
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
     -Assyrian stone tablet, c.2800 BC                         ben@morrow.me.uk


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

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


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